Maximize with multiple variable

46 views
Skip to first unread message

Dilly Day

unread,
Feb 15, 2021, 3:01:12 AM2/15/21
to choco-solver
Hi.
I am new to constraint programming and choco solver. I tryed to use this  website exemple to maximise 3X + 4Y
 
        Model model = new Model();
IntVar OBJ = model.intVar("objective", 0, 999);
IntVar X= model.intVar("x",0,1000);
IntVar Y= model.intVar("y",0,1000);

model.scalar(new IntVar[]{X,Y}, new int[]{3,4}).post();
// Specify objective
model.setObjective(Model.MAXIMIZE, OBJ);
// Compute optimum
model.getSolver().solve();



But i have this error "Cannot resolve method 'scalar(org.chocosolver.solver.variables.IntVar[], int[])' " and I don't know why.
Any help is appreciated

wkau...@gmail.com

unread,
Feb 15, 2021, 4:33:11 AM2/15/21
to choco-solver
Hello Dilly Day

Your problem is in this instruction: model.scalar(new IntVar[]{X,Y}, new int[]{3,4}).post();
So you have forgotten to add the OBJ variable like that: 
model.scalar(new IntVar[] {X, Y}, new int[] {3, 4},"=",OBJ).post(); 

I correct it and after the execution I have obtened X=333 and Y=0.

I hope I answered your question?
Reply all
Reply to author
Forward
0 new messages