1

I've been experiencing with GAMS but I still haven't got a clue what I'm doing. Can someone take a look at this short model and try to point me in the right direction? I have problems in the compilation at the equations, getting a few of these: Dimension different - The symbol is referenced with more/less indices as declared Uncontrolled set entered as constant

Sets
        i months / 1, 2, 3 /
        j months / 1, 2, 3 /;

Parameters
         cp(i)  production cost in month i
         /        1     1.08
                  2     1.11
                  3     1.10
                                   /

         rh(i)  number of necessary workers in month i
         /        1     3
                  2     4
                  3     6
                                     /

        cap(i)  production capacity in month i
         /        1     25
                  2     20
                  3     25
                                       /
         q(j)  number of motors to deliver in month j
         /        1     10
                  2     15
                  3     25
                                 /

Scalar ca  cost to store motors for a month /0.15/ ;

variables
    mc(i,j) cost of production of motors in month i to be delivered in month j
    x(i,j)  number of motors produced in month i to be delivered in month j;


free variables
    wf workforce

    z cost of production
    hr human resources;

Equations
    cost cost 
    human_resources human resources
    r1 restriction1
    r2 restriction2 ;

cost .. z  =e=  sum((i,j), (cp(i)+(j-i)*ca)*x(i,j)) ;
human_resources .. hr =e= sum(i, sum(j, rh(i)*x(i, j))) ;
*lower than
r1..   sum(j, x(i,j))  =l=  cap(i) ;
*greater than
r2.. sum(i, x(i,j))  =g=  q(j) ;

Model
    motors 'temp' /all/;

Solve motors using mip minimizing mc;

Display mc, x;
rkza
  • 53
  • 3

1 Answers1

1

This works but check the solution. I added the positive variable x because otherwise you would have negative productions. The main problem was the fact that you were optimizing a variable that is declared but that you never use in the equations. Also, the variable you are optimizing cannot have to dimensions (I think). Then, for constraints r1 and r2 you need to add an index because they must be verified for each month, so r1(i) and r2(j). They are actually a "family of constraints". You cannot subtract the indexes of the months (can't explain why), but you can subtract their order in the set.
And finally, calculate the mc(i,j) as a parameter after you have obtained the solution.

Sets
        i months / 1, 2, 3 /
        j months / 1, 2, 3 /;

Parameters
         cp(i)  production cost in month i
         /        1     1.08
                  2     1.11
                  3     1.10
                                   /

         rh(i)  number of necessary workers in month i
         /        1     3
                  2     4
                  3     6
                                     /

        cap(i)  production capacity in month i
         /        1     25
                  2     20
                  3     25
                                       /
         q(j)  number of motors to deliver in month j
         /        1     10
                  2     15
                  3     25
                                 /

Scalar ca  cost to store motors for a month /0.15/ ;

variables
*    mc(i,j) cost of production of motors in month i to be delivered in month j
    x(i,j)  number of motors produced in month i to be delivered in month j;

positive variable x;
free variables
    wf workforce

    z cost of production
    hr human resources;

Equations
    cost cost
    human_resources human resources
    r1(i) restriction1
    r2(j) restriction2 ;

cost .. z  =e=  sum((i,j), (cp(i)+(ord(j)-ord(i))*ca)*x(i,j)) ;
human_resources .. hr =e= sum(i, sum(j, rh(i)*x(i, j))) ;
*lower than
r1(i)..   sum(j, x(i,j))  =l=  cap(i) ;
*greater than
r2(j).. sum(i, x(i,j))  =g=  q(j) ;

Model
    motors 'temp' /all/;

Solve motors using mip minimizing z;

Parameter mc(i,j);
mc(i,j)= (cp(i)+(ord(j)-ord(i))*ca)*x.l(i,j);
Display mc, x.l;

  • first of all, thanks a lot! It did help. I now have another problem... I think it is a simple thing but I can't find an answer anywhere. the question is below, if you could take a quick look! https://stackoverflow.com/questions/62134823/how-to-add-a-condition-to-a-variable-gams thanks again!! – rkza Jun 01 '20 at 18:36