help-glpk
[Top][All Lists]
Advanced

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

RE: [Help-glpk] Strange Error with if/then/else


From: Robert Fourer
Subject: RE: [Help-glpk] Strange Error with if/then/else
Date: Sun, 6 Apr 2008 22:51:50 -0500

If for every i in STUDENT and j in CHOICE, Student_Choice[i,j] is a member
of COURSE, then I would be tempted to try

  maximize z: sum {i in STUDENT, l in GROUP, j in CHOICE}
    StudentDistribution[i,Student_Choice[i,j],l] * Satisfaction[j];

This assumes that Student_Choice[i,j] is not a variable, among other things.
There is no logical reason why variables can't appear in if-expressions or
in subscripts, it's just that not all modeling languages have evolved to
handle these possibilities.

Bob Fourer
address@hidden


> -----Original Message-----
> From: address@hidden [mailto:help-
> address@hidden On Behalf Of Jonathan
> Klein
> Sent: Saturday, April 05, 2008 12:37 PM
> To: address@hidden
> Subject: Re: [Help-glpk] Strange Error with if/then/else
> 
> Hi,
> the short example was just du have an minimal example where the error
> occurs.
> I managed it to rewrite my Problem to something like this:
> 
> maximize z: sum{i in STUDENT, l in GROUP, k in COURSE, j in CHOICE}
>                       if k==Student_Choice[i, j]
>                       then StudentDistribution[i,k,l] * Satisfaction[j]
>                       else 0;
> 
> which has the same effect, but was no variable in the test sentence.
> But is there any good reason why i cant have a varaible in there?
> 
> Jonathan
> 
> 
> Leandro Barcelos schrieb:
> > correcting...
> >
> > You can't put the variable in the test sentence of the if-then-else.
> >
> > On Sat, Apr 5, 2008 at 2:13 PM, Leandro Barcelos
> > <address@hidden <mailto:address@hidden>> wrote:
> >
> >     Jonathan,
> >
> >     Try:
> >     maximize Anzahl : sum{i in PEOPLE} x[i];
> >
> >     That's the same.
> >
> >     The problem with your equation is that you can't put if-then-else in
> >     a linear equation
> >
> >     cya
> >
> >
> >
> >     On Sat, Apr 5, 2008 at 10:36 AM, Jonathan Klein
> >     <address@hidden <mailto:address@hidden>> wrote:
> >
> >         Hi,
> >
> >         i havbe a very simple Problem like this:
> >
> >         set PEOPLE;
> >         var x{i in PEOPLE} binary;
> >         maximize Anzahl : sum{i in PEOPLE} (if x[i]==1 then 1 else 0);
> >         data;
> >         set LEUTE:=Hans Joachen Peter Klaus;
> >         end;
> >
> >         And i get the Error: operator preceding == has invalid type
> >
> >         I know, that this problem doesn't make sense, but i have i
> >         somewhat more complex problem in wich i get the same error:
> >
> >
> >
> >
> >         # Berufsinformationstag
> >
> >         set STUDENT;#i
> >         set CHOICE;#j
> >         set COURSE;#k
> >         set GROUP;#l
> >
> >         param Student_Choice {i in STUDENT, j in CHOICE} symbolic in
> >         COURSE;# Welcher Schüler welche Wünsche hat
> >         #param Course_Minimum {k in COURSE};#Wie viele Schüler eine
> >         Veranstaltung minimal braucht
> >         #param Course_Maximum {k in COURSE};#Wie viele Schüler eine
> >         Veranstaltung haben darf
> >         param Satisfaction {j in CHOICE};#für jeden wunsch die Menge,
> >         wie glücklich er ist
> >
> >
> >         var TimeTable{k in COURSE, l in GROUP}, binary;
> >         var StudentDistribution {i in STUDENT, k in COURSE, l in GROUP}
> >         binary ;
> >
> >         # wenn sich der schüler die aktuelle veranstaltung wünscht und
> >         in der veranstaltung in dieser gruppe ist
> >         maximize z: sum{i in STUDENT, l in GROUP, k in COURSE, j in
> CHOICE}
> >                                (if 1==StudentDistribution[i,k,l]
> >                                and k==Student_Choice[i, j]
> >                                then Satisfaction[k] else 0);
> >
> >
> >
> >
> >
> >         So i have Students that are in different Courses, in 1 Course
> >         per Group. They coose 6 Courses and will be in 4 (1 in each
> >         group). If they are in a grout that the have choosen, they are
> >         happy.
> >         So i have to check for every Choice of every Student in every
> >         Course in every Group if the student is in this course in this
> >         group and if he had choosen it. If so, he gets as much happiness
> >         as his choice had importance.
> >
> >         At the end i need to know form every Student in which courses he
> >         ist an which courses in which group have to take place, so i
> >         have choosen the binary variables.
> >
> >         I dont konw why the types should not match, because
> >         StudentDistribution ist binary, so i can only be 0 or 1 an
> >         Student_Choice has to be a COURSE.
> >
> >         I studiet the language reference manual for a long time and
> >         looked at many examples with if/then/else but i still have no
> >         idea what i'm doing wrong.
> >
> >         PS: I use C++ for 5 years now, but im relativly new to GNU
> >         MathProg :(
> >
> >         I would be very gald for every help.
> >
> >         Jonathan
> >
> >
> >         _______________________________________________
> >         Help-glpk mailing list
> >         address@hidden <mailto:address@hidden>
> >         http://lists.gnu.org/mailman/listinfo/help-glpk
> >
> >
> >
> >
> >     --
> >     Leandro B. Barcelos
> >
> >
> >
> >
> > --
> > Leandro B. Barcelos
> 
> 
> 
> _______________________________________________
> Help-glpk mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/help-glpk






reply via email to

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