Originally posted by: SN2683
Thank you very much for your prompt response. I appreciate it.
We edited the source code a bit and we were able to achieve the object below.
using CP;
tuple t
{
int ID;
int thickness;
int Widths;
}
{t} s=
{
<1, 170 , 50 >,
<2 , 160 , 30 >,
<3 , 200 , 40 >,
<4 , 150 , 40 >,
<5 , 180 , 30 >,
<6 , 230 , 50 >,
<7 , 140 , 70 >,
<8 , 200 , 50 >
// ,<9 , 215 , 60 >
};
int thickness[i in 1..card(s)]=item(s,i-1).thickness; //card(s)で配列数を取得
int Widths[i in 1..card(s)]=item(s,i-1).Widths;
dvar int which[1..card(s)] in 1..card(s); // which slab is at position i ?
dvar int nbOk; // number of constraints that are ok
maximize nbOk;
subject to
{
allDifferent(which);
//nbOk==
//(abs(thickness[which[1]]-thickness[which[card(s)]])<=20)
//+sum(i in 1..card(s)-1) (abs(Widths[which[i]]-Widths[which[i+1]])<=10);
//Edited constraint by me is here.
nbOk==
sum(i in 1..card(s)-1)
(abs(thickness[which[i]]-thickness[which[i+1]])<=20) *
(abs(Widths[which[i]]-Widths[which[i+1]])<=10)
;
}
{t} result={item(s,which[i]-1) | i in 1..card(s)};
execute
{
writeln(result);
}
****************
If possible, I would like to realize another purpose at the same time.
I would like to arrange the values multiplied by thickness and width so that they are as large as possible.
For example, it is as follows.
<A>
ID thickness Width thickness*Width
--- ---------- ------ -----------------
6 230 50 11500
7 140 70 9800
8 200 50 10000
3 200 40 8000
5 180 30 5400
2 160 30 4800
4 150 40 6000
1 170 50 8500
<B>
ID thickness Width thickness*Width
--- ---------- ------ ------------------
1 170 50 8500
4 150 40 6000
2 160 30 4800
5 180 30 5400
3 200 40 8000
8 200 50 10000
7 140 70 9800
6 230 50 11500
Both of the above satisfy the original rules and are sorted in reverse order.
<A>:6→7→8→3→5→2→4→1
<B>:6←7←8←3←5←2←4←1
But A is lined up in order of larger value multiplied by thickness and width.
Is it possible with CPLEX to prioritize output results from A over B?
Thank you very much.
#DecisionOptimization#OPLusingCPLEXOptimizer