Dear all,

I am having a problem with Equation part of my gams code. If you check initial_balance and balance equations , you'll see what is my problem and what I want to do.

For initial_balance equation I want to assign Jun for t and for balance eq. I want to assign t-1 for store variable.

I would be glad if you help me .

Sets

t 'Months' /Jan,Feb,Mar,Apr,May,Jun/

p 'Products' /1,2,3,4,5,6,7/

m 'Machines' /Gr,VD,HD,Br,Pl/ ;

Parameters

profit(p) 'Profit of product p'

/1 10

2 6

3 8

4 4

5 11

6 9

7 3/

installed(m) ' Number of machines of type m installed in the factory'

/Gr 4

VD 2

HD 3

Br 1

Pl 1/;

Table

down(t,m) 'Number of machines of type m scheduled for maintenance at month t'

Gr VD HD Br Pl

Jan 1 0 0 0 0

Feb 0 0 2 0 0

Mar 0 0 0 1 0

Apr 0 1 0 0 0

May 1 1 0 0 0

Jun 0 0 1 0 0

Table

time_req(m,p) 'Time (in hours/unit) needed on machine m to manufacture one unit of product p'

1 2 3 4 5 6 7

Gr 0.5 0.7 0 0 0.3 0.2 0.5

VD 0.1 0.2 0 0.3 0 0.6 0

HD 0.2 0 0.8 0 0 0 0.6

Br 0.05 0.03 0 0.07 0.1 0 0.08

Pl 0 0 0.01 0 0.05 0 0.05 ;

Table

max_sales(t,p) 'Maximum number of units of product p that can be sold at month t'

1 2 3 4 5 6 7

Jan 500 1000 300 300 800 200 100

Feb 600 500 200 0 400 300 150

Mar 300 600 0 0 500 400 100

Apr 200 300 400 500 200 0 100

May 0 100 500 100 1000 300 0

Jun 500 500 100 300 1100 500 60 ;

Parameter

holding_cost 'Monthly cost (in USD/unit/month) of keeping in inventory a unit of any product type'

store_target 'Number of units of each product type to keep in inventory at the end of the planning horizon'

hours_per_month 'Time (in hours/month) available at any machine on a monthly basis'

max_inventory 'Maximum number of units of a single product type that can be stored in inventory at any given month ';

holding_cost=0.5;

hours_per_month=2*8*24 ;

max_inventory=100;

Variables

make(t,p) ' Number of units of product p to manufacture at month t'

store(t,p) 'Number of units of product p to store at month t'

sell(t,p) 'Number of units of product p to sell at month t'

z 'The total profit of the planning horizon' ;

Positive Variables

make

store

sell;

Equations

initial_balance(t,p) 'For each product p, the number of units produced should be equal to the number of units sold plus the number stored'

balance(t-1,p) 'For each product p, the number of units produced should be equal to the number of units sold plus the number stored'

machine_cap(m,t) 'Total time used to manufacture any product at machine type m cannot exceed its monthly capacity'

store_cap(t,p) 'Quantity of product p that stored must be lower or equal to 100'

sell_cap(t,p) 'Max sell must be equal or lower than'

maxprofit 'obj function' ;

maxprofit.. z=e=sum(t,sum(p,profit(p)*make(t,p)-holding_cost*store(t,p)));

initial_balance(Jun,p).. make(Jun,p)=e=sell(Jun,p)+store(Jun,p);

balance(t-1,p).. store(t-1,p)+make(t,p)=e=sell(t,p)+store(t,p);

machine_cap(m,t).. sum(p,time_req(m,p)*make(t,p))=l=hours_per_month*(installed(m)-down(t,m));

store_cap(t,p).. store(t,p)=l=max_inventory ;

sell_cap(t,p).. sell(t,p)=l=max_sales(t,p);

Model Untitled_2 /all/;

Solve Untitled_2 using LP maximizing z;

## Problem with writing equation Topic is solved

### Re: Problem with writing equation

you should use 'Jun' instead of Jun and remove it from equation index as follows:

initial_balance(p).. make('Jun',p)=e=sell('Jun',p)+store('Jun',p);

You can write balance equation as follows:

balance(t,p)$(ord(t) ne 1).. store(t-1,p)+make(t,p)=e=sell(t,p)+store(t,p);

This will include the equation starting from Feb and you will not face error because of t-1.

If there is some initial store, you can do the following:

balance(t,p).. store(t-1,p)$(ord(t) ne 1)+ initial_store(p)$(ord(t) eq 1) + make(t,p)=e=sell(t,p)+store(t,p);

Hope this helps.

- Atharv

initial_balance(p).. make('Jun',p)=e=sell('Jun',p)+store('Jun',p);

You can write balance equation as follows:

balance(t,p)$(ord(t) ne 1).. store(t-1,p)+make(t,p)=e=sell(t,p)+store(t,p);

This will include the equation starting from Feb and you will not face error because of t-1.

If there is some initial store, you can do the following:

balance(t,p).. store(t-1,p)$(ord(t) ne 1)+ initial_store(p)$(ord(t) eq 1) + make(t,p)=e=sell(t,p)+store(t,p);

Hope this helps.

- Atharv