How to Define a Constraint Using If-Then-Else for Vegetable Growth?

  • Context: Undergrad 
  • Thread starter Thread starter Alexx1
  • Start date Start date
  • Tags Tags
    Construction
Click For Summary

Discussion Overview

The discussion revolves around defining constraints for vegetable growth using an IF-THEN-ELSE structure in the context of optimization programming, specifically within IBM ILOG CPLEX Optimization Studio. Participants explore how to express conditions relating the amount of vegetable growth to binary indicators of whether vegetables are grown on specific patches.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • Alex proposes a constraint where if the amount of vegetable i on patch k is greater than zero, then y[i][k] must equal 1, and if it is zero, y[i][k] must equal 0.
  • One participant suggests a simplified expression: y[i][k] = (b[i][k] > 0).
  • Another participant mentions that if b[i][k] is never negative, y[i][k] could be expressed as y[i][k] = sgn(b[i][k]).
  • Alex expresses that neither proposed constraints are accepted in CPLEX, indicating a need for a different formulation.
  • One participant references Wikipedia, suggesting the use of an IF-THEN-ELSE construct supported by OPL, questioning why Alex does not use it.
  • Another participant provides examples from IBM's manual on OPL, demonstrating the use of a ternary operator to express the desired constraints.
  • There is a clarification that the ternary operator is similar to constructs in the C programming language, which may aid in formulating the constraints.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the best way to express the constraints within CPLEX. There are multiple competing views on how to formulate the conditions effectively.

Contextual Notes

Participants express uncertainty regarding the acceptance of various constraint formulations in CPLEX, and there are limitations in the proposed solutions based on the programming language's capabilities.

Alexx1
Messages
86
Reaction score
0
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[k] = amount of vegetable i growing on patch k
y[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[k] > 0), vegetable i must be assigned to patch k (i.e. y[k] = 1)
I was thinking that it could be something like that:

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

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

What do you guys think?

Kind regards,
Alex
 
Last edited:
Physics news on Phys.org
Hi Alexx1!

Perhaps like this?
y[k] = (b[k] > 0);
 
If you know that b[k] will never be negative, you have y[k] = sgn( b[k] ).
 
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
 
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?
 
Michael Redei said:
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?
 
Here's some examples from IBM's manual on OPL:
Code:
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[k] = (b[k] > 0) ? 1 : 0;
 
That is a ternary operator like the one in the C language:
Code:
                   if()               then             else
int variable=(boolean statement) ? [when true] : [when false];

The example on line two above "concatenates" or nests operators
Code:
int signValue = (value>0) ? 1 :[/color] (value<0) ? -1 : 0;[/color]

Maybe that will help...
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 29 ·
Replies
29
Views
5K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 17 ·
Replies
17
Views
2K
  • · Replies 28 ·
Replies
28
Views
3K
  • · Replies 27 ·
Replies
27
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
647