← 输入框|github.com|刷新
Skip to content

Weird behavior in simple problem #4

Open

Description

@markjreed

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.

Activity

  1. changed the title [-]What's happening here?[/-] [+]Weird behavior in simple problem[/+] on Sep 18, 2022
  2. FCO commented on Jul 25, 2023

    @FCO
    Owner

    Thanks for your message. Sorry for taking so long to respond. I’ll take a look at it as soon as possible, when I’m back home from vacation. Thanks

  3. self-assigned this
    on Jul 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions