Help save net neutrality! Learn more.
Close

import for Constraint

Help
2009-10-12
2013-04-06
  • Patrick Prosser

    Patrick Prosser - 2009-10-12

    What do I have to import so that I can do the following?

         Constraint exp = or(neq(z, y),  leq(z,9) );

     
  • Arnaud Malapert

    Arnaud Malapert - 2009-10-12

        import choco.Choco.*;

    Best regards, 
    Arnaud

     
  • Julien Menana

    Julien Menana - 2009-10-12

    import static choco.Choco.*;

     
  • Patrick Prosser

    Patrick Prosser - 2009-10-12

    That doesn't work. This appers to be the minimal set of imports (below). How can it be reduced? (I am accessing the jar file via environment variables and running from a command line (old school or what))

    //
    // Compare propagation of allDiff with clique of neq
    // Note: problem is insoluble
    //

    import static choco.Choco.*;
    import choco.cp.model.CPModel;
    import choco.cp.solver.CPSolver;
    import choco.kernel.model.Model;
    import choco.kernel.solver.Solver;
    import choco.kernel.model.variables.integer.IntegerExpressionVariable;
    import choco.kernel.model.variables.integer.IntegerVariable;
    import choco.kernel.solver.ContradictionException;

    import choco.kernel.model.constraints.Constraint;

    public class Prop0 {

      public static void main(String args) throws ContradictionException {

        Model m = new CPModel();
        IntegerVariable x = makeIntVar("X",1,2);
        IntegerVariable y = makeIntVar("Y",1,2);
        IntegerVariable z = makeIntVar("Z",1,2);

        Constraint c_xy = neq(x,y);
        Constraint c_xz = neq(x,z);
        Constraint c_yz = neq(y,z);

        m.addConstraint(c_xy);
        m.addConstraint(c_xz);
        m.addConstraint(c_yz);

        System.out.println(m.pretty());

        Solver s = new CPSolver();
        s.read(m);
        s.propagate();

        System.out.println(s.pretty());   // propagation has no effect

        System.out.println(s.solve());
      }
    }

     
  • Charles Prud'homme

    Hi,

    What doesn't work?

    You cannot reduce the import more than what you have done:

        import static choco.Choco.*;
        import choco.cp.model.CPModel;
        import choco.cp.solver.CPSolver;
        import choco.kernel.model.constraints.Constraint;
        import choco.kernel.model.variables.integer.IntegerVariable;
        import choco.kernel.model.Model;
        import choco.kernel.solver.ContradictionException;
        import choco.kernel.solver.Solver;

    Hope it helps,

    Charles

     
  • Charles Prud'homme

    Sorry, you can reduce it by using only CPxxx object and avoid declaring Constraint objects.

        import static choco.Choco.*;                                           
        import choco.cp.model.CPModel;                                           
        import choco.cp.solver.CPSolver;                                         
        import choco.kernel.model.variables.integer.IntegerVariable;             
        import choco.kernel.solver.ContradictionException;                       
                                                                                 
        public class sandbox {                                                   
                                                                                 
            public static void main(String args) throws ContradictionException {
                                                                                 
            CPModel m = new CPModel();                                           
            IntegerVariable x = makeIntVar("X",1,2);                             
            IntegerVariable y = makeIntVar("Y",1,2);                             
            IntegerVariable z = makeIntVar("Z",1,2);                             
                                                                                 
            m.addConstraint(neq(x,y));                                           
            m.addConstraint(neq(x,z));                                           
            m.addConstraint(neq(y,z));                                           
                                                                                 
            System.out.println(m.pretty());                                      
                                                                                 
            CPSolver s = new CPSolver();                                         
            s.read(m);                                                           
            s.propagate();                                                       
                                                                                 
            System.out.println(s.pretty());   // propagation has no effect       
                                                                                 
            System.out.println(s.solve());                                       
            System.out.println(s.pretty());                                      
                                                                                 
          }                                                                      
        }                                          

    Charles

                                 

     

Log in to post a comment.