help-glpk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-glpk] Variable constraint


From: Andrew Makhorin
Subject: Re: [Help-glpk] Variable constraint
Date: Sat, 17 Oct 2009 14:51:26 +0400

> How should I implement a constraint like the following one using the
> GLKP API?

> s.t. c{i in 1..N} :
>  w[i] <= x[i] * M;

> x[i] is a binary variable.

> I tried to do something like this:

> for (int i=1; i <= N; i++) {
>      glp_set_row_bnds(lp, i, GLP_UP, 0.0, glp_get_col_prim(lp, i)*M);
>      ia[i] = i, ja[i] = i, ar[i] = 1;
>   }

> Is it right to use the glp_get_col_prim routine in this case?

No, your code is wrong.

You should convert your instance to the standard formulation
as required by glpk api (for details see the reference manual).

In particular, the constraint:

  s.t. c{i in 1..N} :
   w[i] <= x[i] * M;

should be written as:

  w[i] - M * x[i] <= 0,  i = 1,...,N

because the right-hand side must be a constant.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]