genetic algorithm

79 views
Skip to first unread message

Nozhan Hosseini

unread,
Apr 19, 2015, 11:16:54 AM4/19/15
to am...@googlegroups.com
Hello again every one , i am working on a project of solving a knapsack problem through genetic algorithm with AMPL

i defined the problem and solved with Default solver of AMPL and got the result but eight now

i am trying to solve heuristic with genetic algorithm

1) i made a random population of all possuible solutions

2) I check the fitness of them in my constraints

now that's time for make mutation and crossover parents to get new children but the problem in my coding is like

ITEM1  0
ITAM2  1
ITEM3 0
ITEM4 0
ITEM5 1
ITEM6 1
ITEM7 0
------------
ITEM1  1
ITAM2  0
ITEM3 0
ITEM4 0
ITEM5 0
ITEM6 1
ITEM7 0
------------
.
.
.



NOW  i want them into a vector or matrice like this
 S1=(0,1,0,0,1,1,0)
S2=(1,0,0,0,0,1,0)
etc
but i don't know how to assign result above to vector type or the code  for this purpose
i would appreciate if you know and answer me

Robert Fourer

unread,
Apr 20, 2015, 11:26:48 AM4/20/15
to am...@googlegroups.com
It is possible to use AMPL's scripting language to implement a heuristic approach to finding solutions for an AMPL model. For program variables like your S1 and S2 you can use indexed parameters, and you can make assignments using AMPL's "let" statement. You can read a complete introduction to AMPL scripting in Chapter 13 of the AMPL book: http://ampl.com/BOOK/CHAPTERS/16-script.pdf.

Bob Fourer
am...@googlegroups.com

=======
Reply all
Reply to author
Forward
0 new messages