Hello Marian,
I wrote the code below. It finds consecutive 1s for each type of plants.
scalar iter /1/, iter2;
scalar value;
parameter count(KW);
count(KW)=0;
while( (iter le card(KW)),
iter2=1;
while( (iter2 le card(t)),
value=SUM(KW$(ord(KW)=iter),Sum(t$(ord(t)=iter2),K.l(KW,t)));
if( value=1,
count(KW)(ord(KW)=iter)=count(KW)(ord(KW)=iter)+1;
else iter2=card(t);
);
iter2=iter2+1;
);
iter=iter+1;
);
From: marian.hofer@yahoo.de
To: hak_kut@hotmail.com
Subject: AW: How to count consecutive binary variables
Date: Thu, 2 Dec 2010 09:19:19 +0100
Hello Hakan,
AN(KW,t) is the decision variable if a power plant is switched on in my unit commitment model.
KW ist standing for the set of different plant types and t is the set for the time steps in hours.
Then I want to count the duration, how long the Plant is switched on without switching off
Von: Hakan Kutucu [mailto:hak_kut@hotmail.com]
Gesendet: Mittwoch, 1. Dezember 2010 19:41
An: sic_marian@yahoo.de
Betreff: RE: How to count consecutive binary variables
Hello PowerM,
in your first message, the decision variable had just one dimension. But now, It has two dimensions. Can you identify the sets KW and t?
After solving the model you cant use decision variables without a suffix.
Date: Wed, 1 Dec 2010 07:37:20 -0800
Subject: Re: How to count consecutive binary variables
From: sic_marian@yahoo.de
To: hak_kut@hotmail.com
Hello Hakan,
I got an eror with your code.
This is the code I have used, since An(KW,t) is the binary variable I
would like to count.
while( (iter le card(t)),
value=Sum(t,An(KW,t)$(ord(t)=iter));
if( value=1,
count=count+1;
else iter=card(t);
);
iter=iter+1;
);
display count;
The error says: A suffix is missing at An(KW,t), I think because
An(KW,t) is a decision variable.
Got any clue, why I can’t count the decision variable?
Best regards
On 1 Dez., 09:25, Hakan Kutucu wrote:
If you want to find first consecutive 1s the following code will help you;
(i should be your set)
scalar iter /1/;
scalar count /0/;
scalar value;
while( (iter le card(i)),
value=Sum(i,K.l(i)$(ord(i)=iter));
if( value=1,
count=count+1;
else iter=card(i);
);
iter=iter+1;
);
display count;
Good luck.
Date: Tue, 30 Nov 2010 23:38:14 +0330
Subject: Re: How to count consecutive binary variables
From: bsaleck...@gmail.com
To: gamsworld@googlegroups.com
Hi.
can you explain more,what exactly you want to do?
I have some thing in mind,maybe helpful.
you want to count number of 1s or just number of variables??
On Tue, Nov 30, 2010 at 10:22 PM, PowerM wrote:
Hi everyone,
i need some hints with counting consecutive binary values.
For Example I want to count the levels from K.1 till K.4
Level
K.1 1
K.2 1
K.3 1
K.4 1
K.5 0
K.6 1
The result should be 4. I am using MIP and K is a binary variable.
Thanks ind advance!!!
–
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/gamsworld?hl=en.
–
Babak Saleck Pay
Group of Industrial Engineering
M.Sc
Operations Research
University of Tehran
Tehran,Iran
–
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/gamsworld?hl=en.
–
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.