help-glpk
[Top][All Lists]
Advanced

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

Re: [Help-glpk] information on presolve results


From: Andrew Makhorin
Subject: Re: [Help-glpk] information on presolve results
Date: Fri, 11 Jan 2008 16:51:37 +0300

> RE: [Help-glpk] information on presolve resultsWas solving a puzzle using
> glpk and wanted to model logical constraints.

> Glpsol says : "Operand preceding = has invalid type"

> Context: s.t. third : if truth[3]=1.......

> Can't the if operator be used this way?

Glpk allows only linear constraints while your constraint is
non-linear due to 'if' operator.

Assuming that 'truth' is binary, you can express the corresponding
condition, say, as the following two constraints, which are linear:

sum{n in N} truth[n] >= truth[3];
sum{n in N} truth[n] <= 1 + M * (1 - truth[3]);

where M is a big number; in this case M can be card(N).

Other conditions can be expressed in a similar way.

As an example see the model 'zebra.mod' included in glpk distribution.

> set N ;

> var own {n in N}, binary;

> var mentions{n in N},binary;

> var truth{n in N}, binary;

> maximize obj: mentions[1];

> subject to first:  truth[1]=own[3];

> s.t. second: truth[2]=1-own[2];

> s.t. third : if truth[3]=1 then sum{n in N}truth[n]=1;

> s.t. CA:( if truth[3]=1 and mentions[1] then own[1] else(1- own[1]))=1;

> s.t. CB:if (truth[3]=1 and mentions[2]) then own[2]=1 else(1- own[2])=1;

> s.t. CC:if (truth[3]=1 and mentions[3]) then own[3]=1 else(1- own[3])=1;


> s.t. owner:sum{n in N}own[n]=1;

> s.t. cmentions: sum{n in N}mentions[n]=1;


> data;

> set N :=1 2 3;

> end;





 







reply via email to

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