Comments (4)
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.
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.
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.
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)
- Consistency of element constraint is sometimes incorrect. HOT 1
- Element constraint sets incorrect `index` value. HOT 1
- XneqC constraints are dropped silently HOT 3
- 4.6 :`RegularExpressionParser` is broken
- ArrayIndexOutOfBoundsException thrown by ExtensionalConflictVA.consistency() on grounded variables HOT 2
- XneqY should not be consistent if X==Y HOT 1
- Please make Arithmetic's fields protected instead of private HOT 3
- NullPointerException in Knapsack.impose() on grounded variables that violate the knapsack capacity HOT 1
- Geost.groundedVars not emptied when Level 1 is removed HOT 2
- geost.ObstacleObjectFrame.timeOnlyCheck() should throw FailExceptions instead of using asserts HOT 2
- Change request to the signature of constructor Channel(IntVar x, Map<Integer,IntVar> bs) HOT 2
- Missing line return in AmongVar.toString() HOT 1
- AmongVar.impose() handles already grounded variables incorrectly
- SoftAllDifferent and SoftGCC incorrectly throw AssertionErrors on infeasible stores HOT 1
- Please make the following protected instead of private HOT 1
- IntDomain should override Domain.clone() to return an IntDomain HOT 1
- IntDomain question HOT 1
- http://jacop.osolpro.com/ no longer functional? HOT 1
- Change request to signatures of Decreasing & Increasing constructors HOT 1
- Change request to XdivYeqZ: make it extend PrimitiveConstraint HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jacop.