Hi,
cplex said:OPL cannot extract expression: sum(h in 1..2) (a(h)(k)(l)*p(h)(i) in my subject,I cannot find the errors and what I should modify.
Thank you very much.
subject to {
forall(i in Demands,k in Demandinstances,l in Supplyitems)
sum(h in Disastertypes) a[h][k][l]*p[h][i][l]*d1[h][i][k]==d2[i][k][l];
}
Topic

Re: Find Errors
20121108T17:00:01ZThis is the accepted answer. This is the accepted answer.Hi
There is several reason why such an error happen. Typical cases are
 Two among a, p and d1 are variable or expression. That is a non linear term whileyou are using cplex. To be sure using constraint programming declare ''using CP'' at first line of the .mod files
 some of the arrays are declared but not filled.
There is other possible case but you should send your project that we can have a look
Hope that helps 
Re: Find Errors
20121109T00:54:05ZThis is the accepted answer. This is the accepted answer. GGR
 20121108T17:00:01Z
Hi
There is several reason why such an error happen. Typical cases are
 Two among a, p and d1 are variable or expression. That is a non linear term whileyou are using cplex. To be sure using constraint programming declare ''using CP'' at first line of the .mod files
 some of the arrays are declared but not filled.
There is other possible case but you should send your project that we can have a look
Hope that helps
This is my project,my data seem to existing problems.I am just contacting cplex this software.Please help me find the errors,thank you very much.
using CP;
int NumWarehouses = ...;
range Warehouses = 1..NumWarehouses;
int Numdisastertypes=...;
range Disastertypes=1..Numdisastertypes;
int Numdemands=...;
range Demands=1..Numdemands;
int Numsupplys=...;
range Supplyitems=1..Numsupplys;
int Numdemandinstances=...;
range Demandinstances=1..Numdemandinstances;
int N=...;
int Q=...;
float Possiblek in Demandinstances=1/10;
//{float} ti in Demands,j in Supplys
int t2i in Demandsj in Warehouses=336;
int t1i in Demandsj in Warehouses=...;
int d1h in Disastertypesi in Demandsk in Demandinstances=...;
int ah in Disastertypesi in Demandsl in Supplyitems=...;
float ph in Disastertypesi in Demandsl in Supplyitems=...;
//int d2i in Demandsk in Demandinstancesl in Supplyitems;
dvar boolean yj in Warehouses;
dvar int+ qj in Warehousesl in Supplyitems;
dvar int+ x1i in Demandsj in Warehousesk in Demandinstancesl in Supplyitems;
dvar int+ x2i in Demandsk in Demandinstancesl in Supplyitems;
dvar int d2i in Demandsk in Demandinstancesl in Supplyitems;
dexpr float objective=sum(k in Demandinstances) Possible[k]*(sum(i in Demands,l in Supplyitems,j in Warehouses) x2[i][k][l]*t2[i][j]+sum(i in Demands,j in Warehouses,l in Supplyitems) x1[i][j][k][l]*t1[i][j])/sum(i in Demands,l in Supplyitems) d2[i][k][l];
minimize objective;
//constraint d2i in Demandsk in Demandinstancesl in Supplyitems;
subject to {
forall(i in Demands,k in Demandinstances,l in Supplyitems)
sum(h in Disastertypes) a[h][k][l]*p[h][i][l]*d1[h][i][k]==d2[i][k][l];
forall(i in Demands,k in Demandinstances,l in Supplyitems)
sum(j in Warehouses) x1[i][j][k][l]+x2[i][k][l]>=d2[i][k][l];
forall(j in Warehouses,k in Demandinstances,l in Supplyitems)
sum(i in Demands) x1[i][j][k][l]<=q[j][l];
forall(j in Warehouses,l in Warehouses)
q[j][l]<=Q*y[j];
sum(j in Warehouses,l in Warehouses)q[j][l]<=Q;
sum(j in Warehouses) y[j]<=N;
}
/*.dat*/
NumWarehouses=4;
Numdisastertypes=2;
Numdemands=6;
Numsupplys=3;
Numdemandinstances=10;
N=3;
Q =30000;
d1=[[ 959 538 784 656 845 576 553 542 591 775
643 527 735 764 874 913 981 700 632 572
879 765 506 583 725 769 502 630 573 927
877 890 669 801 542 998 887 900 568 811
690 967 581 631 614 539 909 716 935 675
784 565 897 827 957 721 934 955 790 757]
[ 701 709 669 621 788 522 774 684 743 909
538 525 950 702 530 584 648 813 718 897
620 951 685 548 617 825 872 890 723 822
562 972 556 566 677 866 594 541 653 689
592 745 890 971 911 824 843 965 754 906
620 745 695 978 508 725 592 888 755 766]];
p=[[http://0.75 0.5 0.25
http://0.5 0.5 0.75
http://0.25 0.25 0.75
http://0.25 0.25 0.75
http://0.5 0.75 0.5
http://0.75 0.5 0.25]
[http://0.75 0.5 0.5
http://0.5 0.5 0.75
http://0.75 0.5 0.25
http://0.75 0.25 0.75
http://0.5 0.75 0.5
http://0.75 0.5 0.25]];
a=[[2 1 1
5 2 4
1 2 3
5 4 4
5 2 4
4 4 5]
[ 5 3 4
2 3 3
4 5 2
2 3 2
1 3 5
4 4 1]];
t1=[ 4 2 5 4
5 3 3 5
2 5 4 4
5 5 2 1
4 2 3 4
1 5 5 5]; 
Re: Find Errors
20121109T17:05:26ZThis is the accepted answer. This is the accepted answer. SystemAdmin
 20121109T00:54:05Z
/*.mod*/
This is my project,my data seem to existing problems.I am just contacting cplex this software.Please help me find the errors,thank you very much.
using CP;
int NumWarehouses = ...;
range Warehouses = 1..NumWarehouses;
int Numdisastertypes=...;
range Disastertypes=1..Numdisastertypes;
int Numdemands=...;
range Demands=1..Numdemands;
int Numsupplys=...;
range Supplyitems=1..Numsupplys;
int Numdemandinstances=...;
range Demandinstances=1..Numdemandinstances;
int N=...;
int Q=...;
float Possiblek in Demandinstances=1/10;
//{float} ti in Demands,j in Supplys
int t2i in Demandsj in Warehouses=336;
int t1i in Demandsj in Warehouses=...;
int d1h in Disastertypesi in Demandsk in Demandinstances=...;
int ah in Disastertypesi in Demandsl in Supplyitems=...;
float ph in Disastertypesi in Demandsl in Supplyitems=...;
//int d2i in Demandsk in Demandinstancesl in Supplyitems;
dvar boolean yj in Warehouses;
dvar int+ qj in Warehousesl in Supplyitems;
dvar int+ x1i in Demandsj in Warehousesk in Demandinstancesl in Supplyitems;
dvar int+ x2i in Demandsk in Demandinstancesl in Supplyitems;
dvar int d2i in Demandsk in Demandinstancesl in Supplyitems;
dexpr float objective=sum(k in Demandinstances) Possible[k]*(sum(i in Demands,l in Supplyitems,j in Warehouses) x2[i][k][l]*t2[i][j]+sum(i in Demands,j in Warehouses,l in Supplyitems) x1[i][j][k][l]*t1[i][j])/sum(i in Demands,l in Supplyitems) d2[i][k][l];
minimize objective;
//constraint d2i in Demandsk in Demandinstancesl in Supplyitems;
subject to {
forall(i in Demands,k in Demandinstances,l in Supplyitems)
sum(h in Disastertypes) a[h][k][l]*p[h][i][l]*d1[h][i][k]==d2[i][k][l];
forall(i in Demands,k in Demandinstances,l in Supplyitems)
sum(j in Warehouses) x1[i][j][k][l]+x2[i][k][l]>=d2[i][k][l];
forall(j in Warehouses,k in Demandinstances,l in Supplyitems)
sum(i in Demands) x1[i][j][k][l]<=q[j][l];
forall(j in Warehouses,l in Warehouses)
q[j][l]<=Q*y[j];
sum(j in Warehouses,l in Warehouses)q[j][l]<=Q;
sum(j in Warehouses) y[j]<=N;
}
/*.dat*/
NumWarehouses=4;
Numdisastertypes=2;
Numdemands=6;
Numsupplys=3;
Numdemandinstances=10;
N=3;
Q =30000;
d1=[[ 959 538 784 656 845 576 553 542 591 775
643 527 735 764 874 913 981 700 632 572
879 765 506 583 725 769 502 630 573 927
877 890 669 801 542 998 887 900 568 811
690 967 581 631 614 539 909 716 935 675
784 565 897 827 957 721 934 955 790 757]
[ 701 709 669 621 788 522 774 684 743 909
538 525 950 702 530 584 648 813 718 897
620 951 685 548 617 825 872 890 723 822
562 972 556 566 677 866 594 541 653 689
592 745 890 971 911 824 843 965 754 906
620 745 695 978 508 725 592 888 755 766]];
p=[[http://0.75 0.5 0.25
http://0.5 0.5 0.75
http://0.25 0.25 0.75
http://0.25 0.25 0.75
http://0.5 0.75 0.5
http://0.75 0.5 0.25]
[http://0.75 0.5 0.5
http://0.5 0.5 0.75
http://0.75 0.5 0.25
http://0.75 0.25 0.75
http://0.5 0.75 0.5
http://0.75 0.5 0.25]];
a=[[2 1 1
5 2 4
1 2 3
5 4 4
5 2 4
4 4 5]
[ 5 3 4
2 3 3
4 5 2
2 3 2
1 3 5
4 4 1]];
t1=[ 4 2 5 4
5 3 3 5
2 5 4 4
5 5 2 1
4 2 3 4
1 5 5 5];
Please, be careful at your indices.
For example, in the expression
forall(i in Demands,k in Demandinstances,l in Supplyitems) sum(h in Disastertypes) a[h][k][l]*p[h][i][l]*d1[h][i][k]==d2[i][k][l];
k will iterate in Demandinstances so in 1..10 although a is defined with
int a[h in Disastertypes][i in Demands][l in Supplyitems]
so
int a[h in 1..2][i in 1..6][l in 1..3]
thus, when k becomes > 6, OPL will raise an error "Index out of bound".
Same issue for the expressions:
sum(j in Warehouses,l in Warehouses) q[j][l]<=...
you should write:
sum(j in Warehouses,l in Supplyitems) q[j][l]<=...
I hope this helps,
Chris. 
Re: Find Errors
20121110T09:26:02ZThis is the accepted answer. This is the accepted answer. ChrisBr
 20121109T17:05:26Z
Hello,
Please, be careful at your indices.
For example, in the expression
<pre class="jivepre">forall(i in Demands,k in Demandinstances,l in Supplyitems) sum(h in Disastertypes) a[h][k][l]*p[h][i][l]*d1[h][i][k]==d2[i][k][l];
</pre>
k will iterate in Demandinstances so in 1..10 although a is defined with
<pre class="jivepre">int a[h in Disastertypes][i in Demands][l in Supplyitems]
</pre>
so
<pre class="jivepre">int a[h in 1..2][i in 1..6][l in 1..3]
</pre>
thus, when k becomes > 6, OPL will raise an error "Index out of bound".
Same issue for the expressions:
<pre class="jivepre">sum(j in Warehouses,l in Warehouses) q[j][l]<=...
</pre>
you should write:
<pre class="jivepre">sum(j in Warehouses,l in Supplyitems) q[j][l]<=...
</pre>
I hope this helps,
Chris.
int t2http://i in 1..6http://j in 1..4=336;
int t1http://i in 1..6http://j in 1..4=...;
int d1http://h in 1..2http://i in 1..6http://k in 1..10=...;
int ahttp://h in 1..2http://i in 1..6http://l in 1..3=...;
float phttp://h in 1..2http://i in 1..6http://l in 1..3=...;
subject to {
forall(i in 1..6,k in 1..10,l in 1..3)
sum(h in 1..2) a[h][k][l]*p[h][i][l]*d1[h][i][k]==d2[i][k][l];
forall(i in 1..6,k in 1..10,l in 1..3)
sum(j in 1..4) x1[i][j][k][l]+x2[i][k][l]>=d2[i][k][l];
forall(j in 1..4,k in 1..10,l in 1..3)
sum(i in 1..6) x1[i][j][k][l]<=q[j][l];
forall(j in 1..4,l in 1..3)
q[j][l]<=Q*y[j];
sum(j in 1..4,l in 1..3)q[j][l]<=Q;
sum(j in 1..4) y[j]<=N;
} 
Re: Find Errors
20121112T13:24:03ZThis is the accepted answer. This is the accepted answer. SystemAdmin
 20121110T09:26:02Z
Firstly,thank you for your helps. I changed the definition and the subject,but the cplex still said"CP cannot extract expression",can you help me?thank you very much.
int t2http://i in 1..6http://j in 1..4=336;
int t1http://i in 1..6http://j in 1..4=...;
int d1http://h in 1..2http://i in 1..6http://k in 1..10=...;
int ahttp://h in 1..2http://i in 1..6http://l in 1..3=...;
float phttp://h in 1..2http://i in 1..6http://l in 1..3=...;
subject to {
forall(i in 1..6,k in 1..10,l in 1..3)
sum(h in 1..2) a[h][k][l]*p[h][i][l]*d1[h][i][k]==d2[i][k][l];
forall(i in 1..6,k in 1..10,l in 1..3)
sum(j in 1..4) x1[i][j][k][l]+x2[i][k][l]>=d2[i][k][l];
forall(j in 1..4,k in 1..10,l in 1..3)
sum(i in 1..6) x1[i][j][k][l]<=q[j][l];
forall(j in 1..4,l in 1..3)
q[j][l]<=Q*y[j];
sum(j in 1..4,l in 1..3)q[j][l]<=Q;
sum(j in 1..4) y[j]<=N;
}
This is the same issue.
In the expression
forall(i in 1..6,k in 1..10,l in 1..3) sum(h in 1..2) a[h][k][l]*p[h][i][l]*d1[h][i][k]==d2[i][k][l];
k will iterate in 1..10 although a is defined with
int a[h in 1..2][i in 1..6][l in 1..3]
so the second index of a can take its values only in 1..6
thus, when k becomes > 6, OPL raises an error "Index out of bound".
Didn't you intend to write "a[h][ i ][l]" instead of "a[h][ k ][l]"?
forall(i in 1..6,k in 1..10,l in 1..3) sum(h in 1..2) a[h][i][l]*p[h][i][l]*d1[h][i][k]==d2[i][k][l];
Regards,
Chris. 
Re: Find Errors
20121113T08:41:34ZThis is the accepted answer. This is the accepted answer. ChrisBr
 20121112T13:24:03Z
Hello,
This is the same issue.
In the expression
<pre class="jivepre">forall(i in 1..6,k in 1..10,l in 1..3) sum(h in 1..2) a[h][k][l]*p[h][i][l]*d1[h][i][k]==d2[i][k][l];
</pre>
k will iterate in 1..10 although a is defined with
<pre class="jivepre">int a[h in 1..2][i in 1..6][l in 1..3]
</pre>
so the second index of a can take its values only in 1..6
thus, when k becomes > 6, OPL raises an error "Index out of bound".
Didn't you intend to write "a[h][ i ][l]" instead of "a[h][ k ][l]"?
<pre class="jivepre">forall(i in 1..6,k in 1..10,l in 1..3) sum(h in 1..2) a[h][i][l]*p[h][i][l]*d1[h][i][k]==d2[i][k][l];
</pre>
Regards,
Chris.