help-glpk
[Top][All Lists]
Advanced

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

Re: [Help-glpk] subspace problem


From: address@hidden
Subject: Re: [Help-glpk] subspace problem
Date: Fri, 08 Feb 2008 23:04:43 +0000
User-agent: Thunderbird 2.0.0.9 (Windows/20071031)

Hi Andrew,

Thank you very much for your detailed reply. I'd like to clarify a point regarding the "max" bit, please scroll down.

Andrew Makhorin wrote:
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

/* VARIABLES */
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.

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

/* CONSTRAINTS */
### 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;
I would like my constraint to capture the idea that a tutee can have at most one tutor, (regardless of the number of rooms which have been assigned), is there any possible way I have express the idea of x{tutee, tutor}, i.e. a subpace of x{tutee, tutor, room}, is there a linear way to do this?
(The constraint that you have specified does not capture this idea)
### 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;

or

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
are in TUTORS x TUTEES x ROOMS.

end;







reply via email to

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