26 new ECLiPSe models, and some changed
Here are my new ECLiPSe models. Almost all are more direct ports of my MiniZinc and Comet models, or at least, they use the same principal approach to the problem. In these ECLiPSe models I have experimented quite a lot, since I like to play with all the bells & whistles in ECLiPSe.
When I started to program in ECLiPSe I tend to use arrays (and arrays of arrays) dominantly since I wanted to access elements via the syntactic sugar of
Update: A comment about this. Some days later (2009-07-16) I found that often (but not always) array access using
a_round_of_golf_propia.ecl: A Round of Golf (Dell Logic Puzzles) (arrays and Propia)
added_corner.ecl: Added corner puzzle
all_interval.ecl: All interval problem (series), (CSPLib problem 7)
among.ecl: (Decomposition of) global constraint among
among_seq.ecl:(Decomposition of) global constraint among_seq
building_blocks.ecl: Building blocks puzzle (for a more general solution see labeling_dice.ecl
circuit.ecl: (Decomposition of) global constraint circuit
clique.ecl: (Decomposition of) global constraint clique
covering_opl.ecl: Set covering, selecting workers (from OPL example covering.mod)
crossword2.ecl: Crossword solving (standard constraint programming example)
cumulative_test.ecl: Test of the built in cumulative constraint
eq10.ecl: Standard benchmark problem
eq20.ecl: Standard benchmark problem
game_theory_taha.ecl: Game theory, zero sum game using eplex (from Taha, Operations Research)
global_cardinality.ecl: (Decomposition of) global constraint global cardinality count (somewhat limited)
global_contiguity.ecl: (Decomposition of) global contiguity
hidato.ecl: Hidato puzzle
inverse.ecl: (Decomposition of) global constraint inverse
kenken2.ecl: KenKen, a grid puzzle
labeled_dice.ecl: Labeled dice puzzle (contains building_blocks.ecl as a problem instance)
safe_cracking.ecl: Safe cracking problem
set_covering_skiena.ecl: Set covering problem (Skiena)
set_partition.ecl: Set partition problem
ski_assignment.ecl: Ski assignment problem
sliding_sum.ecl: (Decomposition of) global constraint sliding sum
stable_marriage.ecl: Stable marriage model (using arrays) sudoku_gcc.ecl: Sudoku, comparison of using ic_global:alldifferent and my decompositions of global cardinality and alldifferent (the rest of the code is from ECLiPSe's Sudoku example)
Who killed Agatha? - now using suspend
Model: who_killed_agatha.ecl
Last I wrote about the problem with accessing for the variable matrices (as arrays):
The updated version uses
for loops: bin_packing2
Model:bin_packing2.ecl
As noted in the updates of Some new ECLiPSe models, e.g. Minesweeper I added a 4'th version of the foreach loop:S #= Weights[J]*(Bins[J] #= B) (note the
When I started to program in ECLiPSe I tend to use arrays (and arrays of arrays) dominantly since I wanted to access elements via the syntactic sugar of
[]
(to mimic MiniZinc/Comet) . But accessing elements via arrays is not always possible, e.g. when both the index variable and the array/matrix contains decision variables, and - as far as I know - the only possible way of accessing these structures are via listut:nth1
on lists. Therefore later models tend to use lists (and nth1
) more.
Update: A comment about this. Some days later (2009-07-16) I found that often (but not always) array access using
[]
on an array of decision variables and index values also decision variables works when lib(propia)
is just loaded (lib(propia)
), even if it is not actually used (i.e. there is not explicit goal such as Goal infers most
). I have already published some variants which is then called _propia.ecl
(maybe _array
would have been better...). For example a_round_of_golf_propia.ecl is so changed. Also, I did a stable marriage model (stable_marriage.ecl) with array access in this way which is much easier to model and understand, than a list/nth1 version..
New ECLiPSe models
a_round_of_golf.ecl: A Round of Golf (Dell Logic Puzzles)a_round_of_golf_propia.ecl: A Round of Golf (Dell Logic Puzzles) (arrays and Propia)
added_corner.ecl: Added corner puzzle
all_interval.ecl: All interval problem (series), (CSPLib problem 7)
among.ecl: (Decomposition of) global constraint among
among_seq.ecl:(Decomposition of) global constraint among_seq
building_blocks.ecl: Building blocks puzzle (for a more general solution see labeling_dice.ecl
circuit.ecl: (Decomposition of) global constraint circuit
clique.ecl: (Decomposition of) global constraint clique
covering_opl.ecl: Set covering, selecting workers (from OPL example covering.mod)
crossword2.ecl: Crossword solving (standard constraint programming example)
cumulative_test.ecl: Test of the built in cumulative constraint
eq10.ecl: Standard benchmark problem
eq20.ecl: Standard benchmark problem
game_theory_taha.ecl: Game theory, zero sum game using eplex (from Taha, Operations Research)
global_cardinality.ecl: (Decomposition of) global constraint global cardinality count (somewhat limited)
global_contiguity.ecl: (Decomposition of) global contiguity
hidato.ecl: Hidato puzzle
inverse.ecl: (Decomposition of) global constraint inverse
kenken2.ecl: KenKen, a grid puzzle
labeled_dice.ecl: Labeled dice puzzle (contains building_blocks.ecl as a problem instance)
safe_cracking.ecl: Safe cracking problem
set_covering_skiena.ecl: Set covering problem (Skiena)
set_partition.ecl: Set partition problem
ski_assignment.ecl: Ski assignment problem
sliding_sum.ecl: (Decomposition of) global constraint sliding sum
stable_marriage.ecl: Stable marriage model (using arrays) sudoku_gcc.ecl: Sudoku, comparison of using ic_global:alldifferent and my decompositions of global cardinality and alldifferent (the rest of the code is from ECLiPSe's Sudoku example)
Some changed models
Here are some changed models.Who killed Agatha? - now using suspend
Model: who_killed_agatha.ecl
Last I wrote about the problem with accessing for the variable matrices (as arrays):
Hates[Killer,Victim] #= 1, Richer[Killer, Victim] #= 0When using this syntax where
Hates
, Killer
, and Victim
are all decision variables, an instantiation fault error was thrown. Earlier I tried some remedies for this (see the cited post).
The updated version uses
suspend
instead:
suspend(Hates[Killer,Victim] #= 1, 2, Killer->inst), suspend(Richer[Killer, Victim] #= 0, 2, Killer->inst),This means that the solver suspends the constraints until
Killer
is instantiated. And in this case it actually works.
suspend
is very powerful and is normally used for creating constraints (propagators). I haven't done this very much yet, but it's in the plans.
for loops: bin_packing2
Model:bin_packing2.ecl
As noted in the updates of Some new ECLiPSe models, e.g. Minesweeper I added a 4'th version of the foreach loop:
Version 4 Use foreach to collect S and then use sum. for(B,1,N), param(Weights,Bins,N,Capacity) do (for(J,1,N), foreach(S,Sum), param(Weights,Bins,B) do S = Weights[J]*(Bins[J] #= B) ), sum(Sum) #=< Capacity ).Again, thanks to Joachim Schimpf for reminding me that one larger constraint
sum(Sum) #=< Capacity
is probably better than more small constraints, such as alot of #=
here).