Giter Club home page Giter Club logo

Comments (4)

radsz avatar radsz commented on August 26, 2024

Hi,

Both solutions are correct. I do not know MagicSeries problem but the constraints are satisfied.
In the first solution you have 6 zeros, 2 ones, 1 two, zero of other numbers.
In the second solution you have 7 zeros, 2 ones, zero of other numbers.

The constraint model corresponds to the solutions.
Why do you claim there is supposed to be only one solution?

best,
Radek

from jacop.

hesrerem avatar hesrerem commented on August 26, 2024

If I understood it correctly, a sequence of numbers S = (s_0 , s_1 ,...,s_{nāˆ’1}) is a magic series, if each s_i represents the number of occurrences of i within the sequence S. For the first solution that is s_0 ~= 6 occurrences of 0, s_1 ~= 2 occurrences of 1, s_2 ~=1 occurrence of 2, and s_6 ~= 1 occurrence of 6. For the second solution that would be:

s_0 ~= 7 occurences of 0 (ok)
s_1 ~= 1 occurrence of 1 (wrong)
s_7 ĀÆ= 1 occurence of 7 (ok)

The one occurs twice instead of just once.

from jacop.

radsz avatar radsz commented on August 26, 2024

Hi,

I was too quick in making my judgement. It seems you found a nice program that exhibits a bug in Among. I am able to replicate your results and with your more detail explanation I can see the problem you are facing. Thank you.

The optimizations applied inside Among that remove the constraint from the constraint store are too quick for your example. For one simple reason, you are using the same variable twice in the context of the constraint (in the context of the list, as well as, the counter). Of course, constraint should account for this but it does not in its optimizations.

It may take some time to figure out a bug fix that does not throw the optimization applied in this constraint. In the meantime, I provide you with a simple workaround (a different model) that does not have this problem.

    store = new Store();

    IntVar[] sequence = new IntVar[n+1];
    IntVar[] counters = new IntVar[n+1];
    for (int i = 0; i < sequence.length; i++) {
        sequence[i] = new IntVar(store, "H" + i, 0, n);
        counters[i] = new IntVar(store, "C" + i, 0, n);
    }

    for (int i=0; i < sequence.length; i++) {
        store.impose(new Among(sequence, new IntervalDomain(i, i), counters[i]));
        store.impose(new XeqY(sequence[i], counters[i]));
    }

This workaround introduces an extra list of variables used as counters that are made equal to the original list. In this model no variable is used twice in the context of the constraint and Among works correctly.

Thank you for persisting in explanation of your problem.

best regards,
Radek

from jacop.

hesrerem avatar hesrerem commented on August 26, 2024

Thanks a lot, works nicely now!
I am looking forward to the fix, which is not urgent though.
Thanks again for looking deeper into the issue.

from jacop.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.