summaryrefslogtreecommitdiffstats
path: root/apps/route/optimizers/route_opt.mzn
diff options
context:
space:
mode:
authorIsaac Manuel Raj <isaac.manuelraj@huawei.com>2020-03-05 11:21:48 +0530
committerIsaac Manuel Raj <isaac.manuelraj@huawei.com>2020-03-05 22:36:12 +0530
commit4779a053f4a64028879711ef8108a554d682549a (patch)
treed6365d120956ccbaec9c424dce2b10375686db19 /apps/route/optimizers/route_opt.mzn
parent7d4f37c45d50c56dfe438c04dbecea3ca9f7c9d2 (diff)
changes in OSDF and optimizer for CCVPN get link requirement.
Changed the model file location as suggested in comments. Issue-ID: OPTFRA-420 Signed-off-by: Isaac Manuel Raj <isaac.manuelraj@huawei.com> Change-Id: I1f4b9a01865a91da1518a250ded48f1b077bed4e
Diffstat (limited to 'apps/route/optimizers/route_opt.mzn')
-rw-r--r--apps/route/optimizers/route_opt.mzn53
1 files changed, 53 insertions, 0 deletions
diff --git a/apps/route/optimizers/route_opt.mzn b/apps/route/optimizers/route_opt.mzn
new file mode 100644
index 0000000..7aa73cb
--- /dev/null
+++ b/apps/route/optimizers/route_opt.mzn
@@ -0,0 +1,53 @@
+
+% Number of nodes
+int: N;
+ % Start node
+0..N-1: Start;
+ % End node
+0..N-1: End;
+ % Number of edges (directed arcs)
+int: M;
+ % The actual edges
+set of int: Edges = 1..M;
+ % Edge lengths
+array[Edges] of int: L;
+ % Edge start node
+array[Edges] of 0..N-1: Edge_Start;
+array[Edges] of 0..N-1: Edge_End;
+
+ % Variable indicating if edge is used
+array[Edges] of var 0..1: x;
+
+constraint
+ forall( i in 0..N-1 ) (
+ if i = Start then
+ % outgoing flow
+ sum(e in Edges where Edge_Start[e] = i)(x[e]) -
+ % incoming flow
+ sum(e in Edges where Edge_End[e] = i)(x[e])
+ = 1
+ elseif i = End then
+ sum(e in Edges where Edge_Start[e] = i)(x[e]) -
+ sum(e in Edges where Edge_End[e] = i)(x[e])
+ = -1
+ else
+ sum(e in Edges where Edge_Start[e] = i)(x[e]) -
+ sum(e in Edges where Edge_End[e] = i)(x[e])
+ = 0
+ endif
+ );
+
+
+solve minimize sum(e in Edges)( L[e] * x[e] );
+%solve satisfy;
+
+output ["Length: ", show(sum(e in Edges)(L[e] * x[e])), "\n"] ++
+ ["Start : ", show(Start), "\n"] ++
+ ["End : ", show(End), "\n\n"] ++
+ ["Edges in shortest path:\n"] ++
+ [ if fix(x[e]) = 1
+ then show(Edge_Start[e]) ++ " -> " ++ show(Edge_End[e]) ++ "\n"
+ else ""
+ endif | e in Edges
+ ];
+