-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.jl
30 lines (30 loc) · 1.24 KB
/
example.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# [[file:fresa.org::examplesolution][examplesolution]]
using Fresa
function objective(x)
# calculate the objective function value
z = 5*x[1]^2 + 4*x[2]^2 - 60*x[1] - 80*x[2]
# evaluate the constraints so that feasible points result in a
# non-positive value, i.e. 0 or less, but infeasible points give a
# positive value. We choose the maximum of both constraints as
# the value to return as an indication of feasibility
g = max( 6*x[1] + 5*x[2] - 60,
10*x[1] + 12*x[2] - 150 )
# return the objective function value along with indication of
# feasibility
(z, g)
end
a = [ 0.0, 0.0 ]
b = [ 8.0, 12.5 ]
initialpopulation = [ Fresa.Point( [4.0, 6.25 ], objective ) ]
best, population = Fresa.solve( objective, # the function
initialpopulation, # initial points
lower = a, # lower bounds
upper = b # upper bounds
)
println("Population at end:")
println("$population")
println("Best solution found is:")
println(" f($( best.x ))=$( best.z )")
println("with constraint satisfaction (≤ 0) or violation (> 0):")
println(" g=$( best.g ).")
# examplesolution ends here