Re: Help: Switching between different objective function
Heinrich Schuchardt <[email protected]> Thu, 26 Nov 2020 20:30:07 +0100
| Newsgroups | gmane.comp.gnu.glpk |
|---|---|
| Message-ID | <[email protected]> |
On 11/26/20 7:55 PM, Manuel Castro wrote:
> Hi there,
>
> I am wondering how I can use an if statement to switch between different
> objective functions.
> For example, how do I represent the following:
>
>
> If (StatusFlag_X == 1 && StatusFlag_Y == 0) then
> minimize cost: sum{i in I, j in J} c[i,j] * x[i,j];
> end if
>
> If (StatusFlag_X == 0 && StatusFlag_Y == 1) then
> minimize cost: sum{i in I, j in J} c[i,j] * x[i,j] + d[i,j] * Y[i,j];
The line above cannot be valid as the indices for d and Y are not
defined. You forgot the parentheses.
> end if
I am assuming StatusFlag_X and StatusFlag_Y are parameters.
The following can be used as template if you have a lot of different
objective functions with complex selection criteria:
minimize cost:
sum{i in {1} : StatusFlag_X == 1 && StatusFlag_Y == 0} 1 *
(sum{i in I, j in J} c[i,j] * x[i,j]) +
sum{i in {1} : StatusFlag_X == 0 && StatusFlag_Y == 1} 1 *
(sum{i in I, j in J} c[i,j] * x[i,j] + d[i,j] * Y[i,j])
In your case this simplifies to:
minimize cost:
sum{i in I, j in J} c[i,j] * x[i,j] +
StatusFlag_Y * sum{i in I, j in J} d[i,j] * Y[i,j]
Best regards
Heinrich
>
> Both are mutually exclusive, i.e. either you do one or the other, i.e.
> both objective functions will never be activate at the same time
>
> This is what I used to do in "mosel" language from FICO Xpress (I don't
> have a license anymore so I am discovering GLPK[Smile] ). How can I do
> this in GLPK language? What's the workaround that we can use for this?
>
> Many thanks in advance for your help. It's really appreciated.
>
> Kind regards,
> Manuel.
>