Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

InvalidCastException in Choco 2.0.1.0-beta

Help
XMan2008
2009-03-10
2013-04-06
  • XMan2008
    XMan2008
    2009-03-10

    Hello people, 

    I wrote an Constraints Editor and a Constraints Solver based on choco and now I am in the testing phase and I found another bug in choco 2.0.1.0 beta. 
    With the editor you can write one or more constraint expressions and check / solve it.

    The Constraint-Solver generates dynamicly the variables and contraints, but the bug exists also by using static code like:

    Model m = new CPModel();
    Solver s = new CPSolver();

    SetVariable Operant1Object = choco.Choco.emptySet();
    SetVariable Operant2Object = choco.Choco.emptySet();

    m.addConstraint(choco.Choco.and(choco.Choco.isIncluded(Operant1Object, Operant2Object), choco.Choco.isIncluded(Operant2Object, Operant1Object)));

    s.read(m);  // here is the InvalidCastException

    "Das Objekt des Typs choco.kernel.model.variables.set.SetConstantVariable kann nicht in Typ choco.kernel.model.variables.integer.IntegerExpressionVariable umgewandelt werden."

    xman2008

     
    • XMan2008
      XMan2008
      2009-03-10

      Note:

      the exception exists also by using, no empty set like:

                  SetVariable Operant1Object = makeVars.makeSetVarStringSet("setV2", 2, 2);

                  SetVariable Operant2Object = makeVars.makeSetVarStringSet("setV3", 3, 3);

      Another question:
      Exists another method to compare the content of two SetVariable
      instead of

      choco.Choco.and(choco.Choco.isIncluded(Operant1Object, Operant2Object), choco.Choco.isIncluded(Operant2Object, Operant1Object))

      ??

      xman2008

       
    • Hi,

      Reifeid constraint can only be used with Integer constraint. Nothing has been implemented for Set Variables concerning reified constraints, but you can state a "AND" constraint just by adding the 2 constraints to your model.

      Charles

       
    • oups, i'm sorry, i've forgotten the second question.
      You can compare 2 setvariables with the eq constraint such as:
      <code>
      Model m1 = new CPModel();        
      SetVariable s1 = Choco.emptySet();
      SetVariable s2 = Choco.emptySet();
      m1.addConstraint(eq(s1, s2));    
      </code>

      It compares the content of the 2 set variables.

      Hope it helps,

      Charles

       
    • XMan2008
      XMan2008
      2009-03-10

      the eq doesn't work with

      int[] intSet2 = {1};
      int[] intSet3 = {2,3,4};

      SetVariable set2 = choco.Choco.makeSetVar("set2", intSet2);
      SetVariable set3 = choco.Choco.makeSetVar("set2", intSet2);

      m.addConstraint(choco.Choco.eq(set2,set3));

      s.solve()

      results in true, but the result of the constraint has to be false;

      It only works by using ranges instead of int arrays.

      xman2008

       
    • What is for you the definition of the results?
      Don't you mix up propagator and checker?

      Charles

       
    • Hi,

      Ok, I get it.
      But, as you are working with Set Variables, the following values represent a solution:
      set2={} and set3={}
      So, that's why s.solve() returns TRUE.

      Do you agree?

      Charles

       
    • XMan2008
      XMan2008
      2009-03-10

      Ahhhhhhhhhhhhhhhhh,

      I found my error in reasoning.

      I have to use

      choco.Choco.constant

      instead of

      makeSetVar.

      Right?

      xman2008

       
    • Hi,

      Just to summarize, when you create a set variable, it represents the intial domain of the variable. So, during the resolution, some values can be removed and lead to an empty set.
      If you want to force the solver to keep every values declared at the creation, you can:
      1/ declare a constant set
      2/ or fix the cardinality of the set variable.

      In your small example, set constant is the right solution.

      Hope it helps,

      Charles

       
    • XMan2008
      XMan2008
      2009-03-11

      I arrive at the conclusion that I can not use the choco-sets for my requirements (automatic generated constraint models).

      The Operations AND and OR etc. has to be work with sets, too.

      I hope, choco supports it in the future.

      Now I handle the sets extern with the option for an integreation with choco in the future.

      Many thanks for your help. Now I understand choco a little bit more than at the beginning.

      xman2008

       
      • Hi,

        If you feel Ok with CHOCO, may be you can try to implement the missing point. It should not be that hard, but it is a little time consumer :)

        Charles