[Top][All Lists]

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

Re: [Help-glpk] subspace problem

From: Andrew Makhorin
Subject: Re: [Help-glpk] subspace problem
Date: Sat, 9 Feb 2008 01:52:35 +0300

> I want to understand the use of "max" in MathProg and how to specify
> "coordinates" in MathProg. I have written a small example to try this out. 

> # author: Benson I.P. Hoi
> # date: Tuesday 05 Feb 2008
> # motivations: 
> # 1. to test max works in MathProg and to check the syntax
> # 2. to test whether the Pre-assignment set PRA works. 

> /* SETS */

> set TUTORS; # a list of tutors
> set TUTEES; # a list of tutees
> set ROOMS; # a list of rooms

> set PRA := {tutor in TUTORS, tutee in TUTEES, r in ROOMS}; # a list of
> pre-assignments of (tutor, tutee, r), is this syntax correct?

> ### sample assignment

> var x {tutor in TUTORS, tutee in TUTEES, r in ROOMS}, binary >= 0; #
> binary variables, 1 if the combination is assigned, 0 otherwise

The condition '>= 0' is not needed, because 'binary' assumes that.

> maximize z: sum{tutor in TUTORS, tutee in TUTEES, r in ROOMS}   x[tutor, 
> tutee,r]  ; # arbritary

> ### all tutees have at most one tutor
> s.t. uniqueTutor{tutee in TUTEES}: sum{tutor in TUTORS} (max{r in ROOMS} 
> x[tutor, tutee, r])<=1;

> # what I want to say is to ignore whatever room has been assigned,
> subspace as x[tutor, tutee] is what I want.. how I express that? Does "max"
> do the trick? GLPK is complaining about syntax. Is there any other to
> express this?

You cannot use variables as operands of max, because this leads to
non-linear constraints. Your constraint can be written as follows:

s.t. uniqueTutor{tutee in TUTEES, r in ROOMS}:
     sum{tutor in TUTORS} x[tutor, tutee, r] <= 1;

> ### pre-assignments to be taken into account
> s.t. preassignment{(tutor, tutee,r) in PRA} x[tutor, tutee, r] =1;

> data;
> set TUTORS := ar3 su2 mrc;
> set TUTEES := iph04 sr104;
> set ROOMS := ra rb rc;
> set PRA := (ar3, iph04, ra) (su2, iph04, rb) (mrc, sr104, rc); 
> # GLPK is complaining that PRA does not need data,why? 
> # iph04 has 2 tutors, I want the MathProg to detect and report this.

This is because you already specified an expression to compute PRA
in the model section:

set PRA := {tutor in TUTORS, tutee in TUTEES, r in ROOMS};

which means that PRA is the cross product TUTORS x TUTEES x ROOMS.
The correct declaration of PRA is the following:

set PRA, dimen 3;


set PRA, in {tutor in TUTORS, tutee in TUTEES, r in ROOMS};

if you want to check that all triplets specified in the data section

> end;

reply via email to

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