Easy problem, begginer needing desperate help!

Problems with syntax of GAMS
Post Reply
rkza
User
User
Posts: 4
Joined: 3 years ago

Easy problem, begginer needing desperate help!

Post by rkza »

Hey guys, so I'm pretty new to GAMS and am trying to figure this out on a rush.
Can anyone point me in the right direction?

I am getting
Dimension different - The symbol is referenced with more/less
indices as declared
at the cost equation and
Uncontrolled set entered as constant
ub the r1 and r2 equations... I can't solve it for nothing :(

Thanks in advance!

Code: Select all

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;
User avatar
bussieck
Moderator
Moderator
Posts: 1042
Joined: 7 years ago

Re: Easy problem, begginer needing desperate help!

Post by bussieck »

Start with the tutorial (https://www.gams.com/latest/docs/UG_Tutorial.html). This gets you quite far since the model handled there is similar to what you do. The only error that is not handled in the tutorial is your (j-i). i and j are set elements (strings) and don't have a numerical value. If they can be converted to represent a numerical value you can use the .val suffix. Here is the code that compiles and executed.

-Michael

Code: Select all

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(i) restriction1
    r2(j) restriction2 ;

cost .. z  =e=  sum((i,j), (cp(i)+(j.val-i.val)*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;

*Display mc.l, x.l;
display z.l, x.l;
rkza
User
User
Posts: 4
Joined: 3 years ago

Re: Easy problem, begginer needing desperate help!

Post by rkza »

Thank you for the quick response! The tutorial was indeed helpful (who would've thought...). I'm feeling a bit stupid for not having a look at it first.
I see what I was doing wrong now.

Anyway, thank you so much for wasting your time with me, and it makes sense now
Post Reply