MIP and conditional constraints

Problems with modeling
Post Reply
cio86
User
User
Posts: 4
Joined: 3 months ago

MIP and conditional constraints

Post by cio86 » 3 months ago

I want to add new contsraints to the following gams code , however i can not integrate these constraints, anyone can help me. I attached constraints.
Especially when 𝑘∈{2,3,17,18,20,25}, how can i specify this?

options limrow=1000,limcol=1000,iterlim=100000000,reslim=36000,optcr=0 ;
set i cities /1*25/;
alias (i,k);
alias (i,j);
alias (i,l);
scalar p //;
scalar q //;
scalar alfa //;

Table d(i,j) distances
....

Parameter O(i) /
......
binary variables x(i,j),
z (i,j);
positive variables f(i,j,k);
free variables amac;
.......;
objective..amac=e=sum((i,k),d(i,k)*O(i)*x(i,k))+sum((i,j,k),alfa*d(i,j)*f(i,j,k))+sum((i,k),d(k,i)*O(i)*x(i,k));
constraint1(i)..sum((j),x(i,j))=e=1;
constraint2(i,j)..x(i,j)=l=x(j,j);
constraint3(i,j)$(ord(i) lt ord(j))..z(i,j)=l=x(i,i);
constraint4(i,j)$(ord(i) lt ord(j))..z(i,j)=l=x(j,j);
constraint5..sum(j,x(j,j))=e=p;
.
.
.
constraint8(i,j,k)$(ord(i) lt ord(j))..f(i,j,k)+f(j,i,k)=l=O(k)*z(i,j);
model transport /all/ ;
option threads=1;
option mip=cplex
solve transport using MIP minimizing amac;
transport.optfile=1;
display amac.l,f.l, x.l, z.l;
Attachments
const.png
constraints
const.png (10.13 KiB) Viewed 524 times

User avatar
Renger
Posts: 112
Joined: 1 year ago

Re: MIP and conditional constraints

Post by Renger » 3 months ago

Hi

You can define a substet of i with the cities to sum over:

Code: Select all

set ks subset of cities /2,3,17,18,20,25/;
and then write your equations using ks instead of k:

Code: Select all

equation 
	atleastonek;

atleastonek..
      sum(ks, X(ks,ks)) =GE= 1;

Same for the two other constraints.

Cheers
Renger

cio86
User
User
Posts: 4
Joined: 3 months ago

Re: MIP and conditional constraints

Post by cio86 » 3 months ago

First of all, thank you very much for your answer. However, when i try this method, i take domain violation for set error.

User avatar
Renger
Posts: 112
Joined: 1 year ago

Re: MIP and conditional constraints

Post by Renger » 3 months ago

Hi
Just show the code...
Renger

cio86
User
User
Posts: 4
Joined: 3 months ago

Re: MIP and conditional constraints

Post by cio86 » 3 months ago

I fixed error. But the result is infeasible due to the 5th constraint.

options limrow=1000,limcol=1000,iterlim=100000000,reslim=36000,optcr=0 ;
set i cities /1*25/;
set ks1 subset of cities /2,3,17,18,20,25/;
set ks2 subset of cities/4,5,6,9,21/;
set ks3 subset of cities/12,14,22,23/;
alias (i,k);
alias (i,j);
alias (i,l);
scalar p /5/;
scalar q /4/;
scalar alfa /0.8/;

Table d(i,j) distances

Parameter O(i) /

binary variables x(i,j),
z (i,j);
positive variables f(i,j,k);
free variables amac;
Equations
objective
constraint1
constraint2
constraint3
constraint4
constraint5
constraint6
constraint7
constraint8
atleastonek1
atleastonek2
atleastonek3;
objective..amac=e=sum((i,k),d(i,k)*O(i)*x(i,k))+sum((i,j,k),alfa*d(i,j)*f(i,j,k))+sum((i,k),d(k,i)*O(i)*x(i,k));
constraint1(i)..sum((j),x(i,j))=e=1;
constraint2(i,j)..x(i,j)=l=x(j,j);
constraint3(i,j)$(ord(i) lt ord(j))..z(i,j)=l=x(i,i);
constraint4(i,j)$(ord(i) lt ord(j))..z(i,j)=l=x(j,j);
constraint5..sum(j,x(j,j))=e=p;
constraint6..sum((i,j)$(ord(i) lt ord(j)),z(i,j))=e=q;
constraint7(i,k)..sum(j$(ord(i) ne ord(j)),f(j,i,k))+O(k)*x(k,i) =e= sum(j$(ord(i) ne ord(j)),f(i,j,k))+ sum((l),w(k,l)*x(l,i));
constraint8(i,j,k)$(ord(i) lt ord(j))..f(i,j,k)+f(j,i,k)=l=O(k)*z(i,j);
atleastonek1(ks1)..sum(j$(ord(j) eq ord(ks1)), x(j,j)) =g= 1;
atleastonek2(ks2)..sum(j$(ord(j) eq ord(ks2)), x(j,j)) =g= 1;
atleastonek3(ks3)..sum(j$(ord(j) eq ord(ks3)), x(j,j)) =g= 1;
model transport /all/ ;
option threads=1;
option mip=cplex
solve transport using MIP minimizing amac;
transport.optfile=1;
display amac.l,f.l, x.l, z.l;

Post Reply