I'm begginer in GAMS. please help me solving this problem

I need to have something like this:

for each   k
   if (sum(i,r(i,k)) >= 1)
     then   u(k) = 1;
     else   u(k) = 0

my code is now this:

set
i /1*2/
j /1*2/
k /1*2/
;

parameters
a(i)     meghdare zobale dar manbae i-om
/1 1, 2 2/

b(j)     zarfiate makane j-om
/1 10, 2 20/

f(k)     hazine sabete istgahe komakie k-om
/1 1, 2 2/

q(k)     zarfiate istgahe komakie k-om (ton)
/1 5, 2 8/

d(k)     hazineye pardazeshe istgahe komakie k-om (ton)
/1 1, 2 7/
;

table
e(k,j)   hazineye haml az istgahe komaki be makane dafe zobaleye j-om
         1       2
1        3       4
2        3       5
;

table
c(i,k)   hazineye haml az manbae i-om be istgahe k-om
         1       2
1        3       4
2        3       5
;

variables
r(i,k)   r=1:entekhabe istagahe komakie k-om baraye manbae i-om   r=0: O.W
z
y(k,j)
n(k)
;

binary variable
u(k)
;

equation
obj
const1
const2
const3
const4
const5
;

obj .. z =e= sum((i,k) , ((c(i,k) + d(k))*a(i)*r(i,k))) +
             sum(k , ( f(k)* u(k))) + sum((k,j) , (e(k,j)*y(k,j)));
const1(i) .. sum(k , r(i,k)) =e= 1;
const2(k) .. sum(i , a(i)*r(i,k)) =l= q(k);
const3(k) .. sum(i , a(i)*r(i,k)) =e= sum (j , y(k,j)) ;
const4(j) .. sum(k , y(k,j)) =l= b(j);
const5(k) .. sum(i , r(i,k)) =e= u(k);

loop(k,
       if((r(i,k)) = 1,
         u(k) = 1
       );
);

model opt /obj , const1 , const2 , const3 , const4 , const5/;
solve opt using lp minimizing z;
display z.l;

can anybody help me to solve this problem?

thanx a lot

asked 21 Jan '13, 17:17

mooshy_nini's gravatar image

mooshy_nini
11
accept rate: 0%

edited 22 Jan '13, 03:59

fbahr's gravatar image

fbahr ♦
4.6k716

What is the problem?

(22 Jan '13, 06:46) jfpuget

I assume you are getting an error since you have a variable "r" in an "if" statement. Presumably you need to provide linear constraints linking the u and r variables (like lots of other recent questions on linking variables).

link

answered 22 Jan '13, 20:45

Michael%20Trick's gravatar image

Michael Trick ♦♦
4.1k41533
accept rate: 20%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×51

Asked: 21 Jan '13, 17:17

Seen: 892 times

Last updated: 22 Jan '13, 20:45

OR-Exchange! Your site for questions, answers, and announcements about operations research.