Skip to content

Instantly share code, notes, and snippets.

@samiranberahaldia
Last active June 21, 2020 20:56
Show Gist options
  • Save samiranberahaldia/e837b24f72f5bd4fb0e108c1beb07ff9 to your computer and use it in GitHub Desktop.
Save samiranberahaldia/e837b24f72f5bd4fb0e108c1beb07ff9 to your computer and use it in GitHub Desktop.
set i Node Indexes /1*5/;
alias(i,j,h);
variable cost Objective Function Value;
binary variable x(i,j) 1 if edge between i to j is active 0 otherwise;
positive variable T(j) Time at node j;
parameters S Source Node /1/, N Destination Node /5/;
table c(i,j) Transportation time from node i to j
1 2 3 4 5
1 2 3 9 8 20
2 7 3 4 6 18
3 6 5 9 5 6
4 8 7 5 4 9
5 8 5 6 8 7;
equations objective_function, same_node(i,j), source_node(i), destination_node(j), flow_constraint(j)
sub_tour_elimination_source(j), sub_tour_elimination_nodes(j);
objective_function.. cost =e= sum((i,j),x(i,j)*c(i,j));
same_node(i,j)$(ord(i)=ord(j)).. x(i,j) =e= 0;
source_node(i)$(ord(i)=1).. sum(j,x(i,j)) =e= 1;
destination_node(j)$(ord(j)=N).. sum(i,x(i,j)) =e= 1;
flow_constraint(j)$(ord(j)<>1 and ord(j)<>N).. sum(i,x(i,j)) =e= sum(h,x(j,h));
sub_tour_elimination_source(j)$(ord(j)=1).. T(j) =e= 0;
sub_tour_elimination_nodes(j)$(ord(j)>1).. T(j) =e= sum(i,x(i,j)*(T(i) + c(i,j)));
model routing /all/;
solve routing using minlp minimizing cost;
display cost.l,x.l;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment