Choosing columns so that sum(rows) are equal 1

Hello,

i got a table b(i,j) which looks like that:
j1 j2 j3 j4 j5 j6 j7 j8 j9
i1 1 0 0 1 0 0 0 1 1
i2 0 1 1 0 0 0 1 0 0
i3 0 1 0 0 1 0 0 0 1
i4 1 0 0 0 0 1 0 0 1
i5 0 0 0 0 0 0 1 1 1
i6 0 0 1 1 0 1 0 0 0

and i got a function F for costs that need to be minimized …
Now i want a restriction that says the sum of each row is exactly 1 and the model shall tell me which j’s are to be used.

I wrote a script in which everything works except for this restriction. The restriction is called NB… in the script. I am pretty sure I need an alias in some way but i cannot get it run without errors … would be very thankful for any help!


Here’s the script:

$title Bonusaufgabe

Sets
i Altersgruppen /i1i6/
j Medientypen /j1
j9/;
alias(i,t)
;

Parameter
r(j) Kosten fuer j /j1 20000, j2 45000, j3 60000, j4 45000, j5 30000, j6 55000, j7 52000, j8 60000, j9 105000/
a(i) Beschränkung jeder Altersgruppe i /i1 1, i2 1, i3 1, i4 1, i5 1, i6 1/
;

table b(i,j)
$include Altersgruppen.txt
;

Variables
ZF Zielfunktionswert
;

positive variables
x(j) gewählte Menge von Medientypen j
;

Equations
ZFkt1 Zielfunktion
NB Nebenbedingung
;

ZFkt1…
ZF =e= sum((j,i), r(j) * x(j));

NB…
sum(t$(ord(t)<=ord(i)), b(j,t)) =e= a(t);

model Bonusaufgabe /ZFkt1,NB/;
solve Bonusaufgabe minimizing ZF using LP;
display ZF.l;

you need to use mixed integer programming instead of linear programming

you need to use mixed integer programming instead of linear programming

Thank you for the hint, of course, but that doesn’t solve my problem with the restriction. I still got some errors. I think it’s a Syntax problem.

What do I need to change in the NB… to get it run? For now i have

NB..
         sum(t$(ord(t)<=ord(i)), a(t) * x(j)) =e= 1;

and the error says

— Starting compilation
— Bonusaufgabe.gms(18) 3 Mb
— .Altersgruppen.txt(7) 3 Mb
— Bonusaufgabe.gms(41) 3 Mb 2 Errors
*** Error 154 in \psf\Home\Downloads\Bonusaufgabe.gms
Set for ‘ord’ is not controlled
*** Error 149 in \psf\Home\Downloads\Bonusaufgabe.gms
Uncontrolled set entered as constant
— Bonusaufgabe.gms(44) 3 Mb 3 Errors
*** Error 257 in \psf\Home\Downloads\Bonusaufgabe.gms
Solve statement not checked because of previous errors
— Bonusaufgabe.gms(45) 3 Mb 4 Errors
*** Error 141 in \psf\Home\Downloads\Bonusaufgabe.gms
Symbol declared but no values have been assigned. Check for missing
data definition, assignment, data loading or implicit assignment
via a solve statement.
A wild shot: You may have spurious commas in the explanatory
text of a declaration. Check symbol reference list.
— Bonusaufgabe.gms(45) 3 Mb 4 Errors
*** Status: Compilation error(s)
— Job Bonusaufgabe.gms Stop 06/15/17 15:19:59 elapsed 0:00:00.044
Exit code = 2

You should define your constraint per user group (“Altersgruppe”):


Equations
ZFkt1 Zielfunktion
*NB Nebenbedingung
NB(i)
;

ZFkt1…
ZF =e= sum((j,i), r(j) * x(j));

*NB…
*sum(t$(ord(t)<=ord(i)), b(j,t)) =e= a(t);

NB(i)…
sum(j,b(i,j)*x(j))=e=1;

That works! Brilliant! Thank you so much :slight_smile: