You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Tried to implement the municipal department numbers problem. Obviously this is a trivial problem that is amenable to a brute-force solution, but I thought it would be a good toy exercise for the constraint solver. However, I'm getting inconsistent results from run to run; it only produces the correct result about half the time, so I wonder if I'm doing something incorrectly.
This is my attempt:
use ProblemSolver;
my ProblemSolver $p .= new;
my @vars = «police sanitation fire»;
for @vars -> $dept {
$p.add-variable($dept, 1..7);
}
$p.unique-vars(@vars);
$p.add-constraint: -> :$police! { $police %% 2 };
$p.add-constraint: -> :$police!, :$sanitation!, :$fire! { $police + $sanitation + $fire == 12 };
.say for $p.solve;
One run will output the correct 14 solutions, while the next will include 16 additional solutions in which the value for police is odd, ignoring the middle constraint above.
The text was updated successfully, but these errors were encountered:
Tried to implement the municipal department numbers problem. Obviously this is a trivial problem that is amenable to a brute-force solution, but I thought it would be a good toy exercise for the constraint solver. However, I'm getting inconsistent results from run to run; it only produces the correct result about half the time, so I wonder if I'm doing something incorrectly.
This is my attempt:
One run will output the correct 14 solutions, while the next will include 16 additional solutions in which the value for
police
is odd, ignoring the middle constraint above.The text was updated successfully, but these errors were encountered: