Register to reply

If-then-else construction

by Alexx1
Tags: construction, ifthenelse
Share this thread:
Alexx1
#1
Dec9-12, 03:51 AM
P: 86
How can we define a constraint saying:

if b is larger than zero then y has to equal 1
if b is equal to zero then y has to equal 0

?

It concerns the following problem:
b[i][k] = amount of vegetable i growing on patch k
y[i][k] = 1 if vegetable i is grown on patch k
= 0 otherwise

So we want to say that if the amount of vegetable i on patch k is larger than zero (i.e. b[i][k] > 0), vegetable i must be assigned to patch k (i.e. y[i][k] = 1)
I was thinking that it could be something like that:

for all i
sum(k) b[i][k]*y[i][k] = b[i][k]

But I don't know if this is correct or not, since you could cancel out both terms b[i][k]

What do you guys think?

Kind regards,
Alex
Phys.Org News Partner Science news on Phys.org
Scientists develop 'electronic nose' for rapid detection of C. diff infection
Why plants in the office make us more productive
Tesla Motors dealing as states play factory poker
I like Serena
#2
Dec9-12, 05:37 AM
HW Helper
I like Serena's Avatar
P: 6,188
Hi Alexx1!

Perhaps like this?
y[i][k] = (b[i][k] > 0);
Michael Redei
#3
Dec9-12, 05:53 AM
P: 181
If you know that b[i][k] will never be negative, you have y[i][k] = sgn( b[i][k] ).

Alexx1
#4
Dec9-12, 12:24 PM
P: 86
If-then-else construction

The thing is I need a constraint to use in the program
IBM ILOG CPLEX Optimization Studio

None of both constraints is accepted in CPLEX
Michael Redei
#5
Dec9-12, 01:03 PM
P: 181
According to Wikipedia's entry on OPL (the programming lanuage used in the program you mention), it does support an IF-THEN-ELSE construct. Why don't you use that?
Alexx1
#6
Dec10-12, 03:41 AM
P: 86
Quote Quote by Michael Redei View Post
According to Wikipedia's entry on OPL (the programming lanuage used in the program you mention), it does support an IF-THEN-ELSE construct. Why don't you use that?
I would prefer stating it in a constraint only using =/>=/<=/</>
Do you know an alternative?
Michael Redei
#7
Dec10-12, 06:31 AM
P: 181
Here's some examples from IBM's manual on OPL:
int value = ...; 
int signValue = (value>0) ? 1 : (value<0) ? -1 : 0;
int absValue = (value>=0) ? value : -value;
It seems that OPL supports a "... ? ... : ..." construct. Have you tried that? E.g.

y[i][k] = (b[i][k] > 0) ? 1 : 0;
jim mcnamara
#8
Dec10-12, 09:17 AM
Sci Advisor
PF Gold
P: 1,384
That is a ternary operator like the one in the C language:
                   if()               then             else
int variable=(boolean statement) ? [when true] : [when false];
The example on line two above "concatenates" or nests operators
int signValue = (value>0) ? 1 : (value<0) ? -1 : 0;
Maybe that will help....


Register to reply

Related Discussions
Information on construction elevators (construction hoists, buck hoists) General Engineering 0
2D Matrix construction Linear & Abstract Algebra 5
Th construction of e General Math 3
The construction of pi General Math 6
Is there a name for this construction? Linear & Abstract Algebra 1