Mathprog text file with 3 parameters related

73 Views Asked by At

I have been trying to do a problem using mathprog method, but i am getting in troubles when i use R to read the txt file.

I think I know where I have the problem but I don't know how to solve it.

Here is the whole code but the problem is in the end when I use in param a and param tc 3 variables:

set I;
/* plants*/

set J;
/* customers*/

set T;
/* types*/

set S;
/* modes*/

param pc{i in I, s in S};
/* variable production cost */

param tc{i in I, j in J, t in T};
/* transportation cost */

param a{i in I, t in T, s in S};
/* quantity of product produced */

param b{j in J, t in T};
/* transportation cost */

var z{i in I, s in S} >= 0;
/* intensity of the plant */

var u{i in I, j in J, t in T} >= 0;
/* amount of product shipped from plant to costumer*/

minimize cost: sum{i in I, s in S} pc[i,s] * z[i,s] + sum{t in T, j in J, i in I} tc[i,j,t] * u[i,j,t];

/* production transportation problem */

s.t. first{i in I, j in J, t in T}: sum{i in I} u[i,j,t] = b[j,t];
/* First Constraint */

s.t. second{i in I, j in J, t in T, s in S}: sum{j in J} u[i,j,t] <= sum{s in S} a[i,t,s] * z[i,s];
/* Second Constraint */

s.t. third{i in I, s in S}: sum{s in S} z[i,s] <= 1;
/* Third Constraint */

s.t. fourth{i in I, s in S}: z[i,s] >= 0;
/* Fourth Constraint */

s.t. fifth{i in I, j in J, t in T}: u[i,j,t] >= 0;
/* Fifth Constraint */

data;

set I := P1 P2;

set J := C1 C2 C3 C4 C5;

set T := T1 T2 T3 T4;

set S := S1;

param pc : S1 :=
P1     5000
P2     7000;

param tc : P1T1 P1T2 P1T3 P1T4 P2T1 P2T2 P2T3 P2T4:= 
C1    10 15 10 20 10 10 12 12
C2    20 10 15 10 12 12 10 15
C3    20 15 10 10 15 10 12 18
C4    10 10 10 10 10 10 10 10
C5    5  10 15 20 20 23 21 15;

param a : S1P1 S1P2 := 
T1    50 100
T2    150 50
T3    200 80
T4    150 200;

param b : T1 T2 T3 T4 := 
C1    80 100 80 120
C2    50 100 105 100
C3    80 105 100 100
C4    80 50 15 100
C5    50  100 150 200;

end;

I use it with these function to read it in R:

model.lp <- Rglpk_read_file ("mathprog_file.txt", type = "MathProg", verbose = F)
1

There are 1 best solutions below

0
Paul G. On

Probably your Rglpk works fine. What I see is some wrong mathprog-syntax.

In your constraints you are are declaring the same index twice:

s.t. first{i in I, j in J, t in T}: sum{i in I} u[i,j,t] = b[j,t];

While having i already defined in the left constraint statement, you are also using i again in the sum statement. You can fix this with a different notation in the sum like {ii in I} and then using the proper i or ii while referencing u.

There is also an error in the definitions of you three dimensional parameters. Have a look a the examples here: explanation of the datablock for an example and explanation on how to do that.