Hi AMPL experts,
I need to input 4-dimensional parameter weight in my optimization problem.
My .dat file is --
data;
set p1 := 1 2 3;
set p2 := 1 2 3;
set l1 := {(1,2,3,4) , (1,2,3) , (1,2)}; # It means if p1 =1 then l1 will be 1,2,3,4,; if p1 =2 then l1 will be 1,2,3; if p1= 3 then l1 will be 1,2
set l2 := {(1,2,3,4,) , (1,2,3) , (1,2)}; # It means if p2 =1, then l2 will be 1,2,3,4,; if p2 =2 then l2 will be 1,2,3; if p2= 3 then l2 will be 1,2
param weight :=
[:,*,*,*]: 1 2 3 :=
1 1 2 1 1/5 1/7
1 2 2 1 1/7 1/9
1 3 2 7 1 1
1 4 2 7 7 1
1 1 3 1 1
1 2 3 1/3 1/5
1 3 3 1/5 1
1 4 3 1/9 1
2 1 3 1 1
2 2 3 5 1
2 3 3 7 5;
In model file following variables are defined.
param weight {p1,l1,p2,l2} >0;
var u {1..p1,1..l1} ;
var t {1..p1,1..l1, 1..p2, 1..l2} ;
The corresponding constraint is :
subject to constraint1 {i in p1, j in l1, s in p2, t in l2: s>i } weight [i,j,s,t] * u[i,j] – u[s,t] = t[i,j,s,t];
My questions are-
The way I defined set l1 and l2 - is it correct?
In data table, l2 has 3 levels (1,2,3; marked in red) for first 4 weights , and l2 has 2 levels (1,2; marked in blue) for next 7 weights. The way I defined param weight table – is it correct? If not, then what is the best approach to input this type of parameter?
Thanks in advance.
--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ampl+uns...@googlegroups.com.
To post to this group, send email to am...@googlegroups.com.
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.
Dr. Robert Fourer;
Thanks for your reply. Based on your suggestions I modified the code. Unfortunately the program still giving me errors. Probably my data input is not in right format.
The following is a short description of my problem.
Suppose I have 3 indexes and each index has different levels. First index has 4 levels, Second index has 3 levels, and Third index has 2 levels.
P1 = 1 2 3; For index p1 =1 , level l1=1 2 3 4; for p1 = 2 , level l2=1 2 3; for p1 =3 then l3=1 2
My variables are combinations of indexes with their levels. For example in this case I have 9 variables, u11,u12,u13,u14,u21,u22,u23,u31,u32.
weight*u11-u21=t1121; weight*u11-u31=t1131; …………(pairwise comparison of all levels of index 1 with all levels of index 2 and 3) {#constraint4}
weight*u21-u31=t2131; …………. (pairwise comparison of all levels of index 2 with all levels of index3) {#constraint4}
Weight is the 4-dimensional parameter for combination of all indexes and levels. In this case I will have 26 weight’s.
I have added some parts of .mod, .dat, .run file and output log. Could you please take a look and let me know where the problem is?
#.mod
param p1 := 6;
set l1 {1..p1} ordered;
param p2 :=6;
set l2 {1..p2} ordered;
param sigma :=3;
param w{i in 1..p1, l1[i], j in 1..p2, l2[j]};
var u{i in 1..p1, l1[i]};
var t {i in 1..p1, l1[i], j in 1..p2, l2[j]};
minimize obj: ……..+ sum{i in 1..p1, a in l1[i], j in 2..p2, b in l2[j] :j>i} t[i,a,j,b]^2;
subject to constraint4{i in 1..p1, a in l1[i], j in 2..p2, b in l2[j] :j>i}: w[i,a,j,b]*u[i,a] - u[j,b]= t[i,a,j,b];
#.dat
data;
set l1[1]=1 2 3 4 5;
set l1[2]=1 2 3 4 5;
set l1[3]=1 2 3 4 5;
set l1[4]=1 2;
set l1[5]=1 2;
set l1[6]=1 2;
set l2[1]=1 2 3 4 5;
set l2[2]=1 2 3 4 5;
set l2[3]=1 2 3 4 5;
set l2[4]=1 2;
set l2[5]=1 2;
set l2[6]=1 2;
param w :=
[:,*,*,*]: 1 2 3 4 5 :=
1 1 2 1 1 0.2 0.142857143 0.111111111
.
.
.
.
1 1 6 1 1 (line 50 of .dat file)
1 2 6 1 1(line 51 of .dat file)
.
.
1 5 6 9 1 (line 54 of .dat file)
.
.
2 3 3 . . . . . (line 57 of .dat file)
.
.
5 2 6 5 1;
The red colors are the values of parameter w for different levels of 3rd column index. Fro example:
1 1 2 1 1 0.2 0.142857143 0.111111 shows the w value’s for level 1,2,3,4,5 of index 2 with compare to first level of first index are 1 1 0.2 0.142857143 0.111111
I used dot for those cases where I don’t have w’values.
#.run
reset;
model inputdata.mod;
data inputdata1.dat;
option solver couenne;
solve;
display {i in 1..p1} u1[i,l1[i]] > inputdata.out;
w[3,1,1,4] is showing in output file. But it can never be like this. The third indices should be greater than 1st indices. It has to be w[3,1,4,1], which is the value w for 1st level of 3rd index compare to 1st level of 4th index.
Again thank you so much for your help.