Details Examples (onetd01)
/***************************************************************/
/* */
/* S A S S A M P L E L I B R A R Y */
/* */
/* NAME: onetd01 */
/* TITLE: Details Examples (onetd01) */
/* PRODUCT: OR */
/* SYSTEM: ALL */
/* KEYS: OR */
/* PROCS: OPTNET, PRINT, SORT, SQL */
/* DATA: */
/* */
/* SUPPORT: UPDATE: */
/* REF: */
/* MISC: Examples from the Details section of the */
/* OPTNET documentation. */
/* */
/***************************************************************/
/* GRAPH INPUT DATA */
/* Link Input Data */
data LinkSetInA;
input from $ to $ weight;
datalines;
A B 1
A C 2
A D 4
;
data LinkSetInB;
input source_node $ sink_node $ value;
datalines;
A B 1
A C 2
A D 4
;
proc optnet
data_links = LinkSetInA;
run;
proc optnet
data_links = LinkSetInB;
data_links_var
from = source_node
to = sink_node
weight = value;
run;
data LinkSetIn;
input from $ to $ weight @@;
datalines;
A B 1 A C 2 A D 4 B C 1 B E 2
B F 5 C E 1 D E 1 E D 1 E F 2
F G 6 G H 1 G I 1 H G 2 H I 3
;
proc optnet
graph_direction = directed
data_links = LinkSetIn
out_nodes = NodeSetOut
out_links = LinkSetOut;
run;
proc print data=NodeSetOut noobs label;
run;
proc print data=LinkSetOut label;
run;
proc optnet
data_links = LinkSetIn
out_nodes = NodeSetOut
out_links = LinkSetOut;
run;
proc print data=LinkSetOut label;
run;
data NodeSetIn;
input label $ @@;
datalines;
A B C D
;
data LinkSetInS;
input from $ to $ weight;
datalines;
A B 1
A C 2
B C 1
;
data CostMatrix;
input back breast fly free;
datalines;
35.1 36.7 28.3 36.1
34.6 32.6 26.9 26.2
31.3 33.9 27.1 31.2
28.6 34.1 29.1 30.3
32.9 32.2 26.6 24.0
27.8 32.5 27.8 27.0
26.3 27.6 23.5 22.4
29.0 24.0 27.9 25.4
27.2 33.8 25.2 24.1
27.0 29.2 23.0 21.9
;
proc optnet
data_matrix = CostMatrix;
data_matrix_var
back--free;
linear_assignment
out = LinearAssign;
run;
/* BICONNECTED COMPONENTS AND ARTICULATION POINTS */
data LinkSetInBiCC;
input from $ to $ @@;
datalines;
A B A F A G B C B D
B E C D E F G I G H
H I
;
proc optnet
data_links = LinkSetInBiCC
out_links = LinkSetOut
out_nodes = NodeSetOut;
biconcomp;
run;
proc print data=LinkSetOut noobs label;
run;
proc print data=NodeSetOut noobs label;
run;
/* CLIQUE */
data LinkSetIn;
input from to @@;
datalines;
0 1 0 2 0 3 0 4 0 5
0 6 1 2 1 3 1 4 2 3
2 4 2 5 2 6 2 7 2 8
3 4 5 6 7 8 8 9
;
proc optnet
data_links = LinkSetIn;
clique
out = Cliques;
run;
proc sql;
create table CliqueSizes as
select clique, count(*) as size
from Cliques
group by clique
order by size desc;
quit;
proc print data=Cliques noobs label;
run;
proc print data=CliqueSizes noobs label;
run;
/* CONNECTED COMPONENTS */
/* Connected Components of a Simple Undirected Graph */
data LinkSetIn;
input from $ to $ @@;
datalines;
A B A C B C C H D E D F D G F E G I K L
;
proc optnet
data_links = LinkSetIn
out_nodes = NodeSetOut;
concomp;
run;
proc print data=NodeSetOut noobs label;
run;
data NodeSetIn;
input node $ @@;
datalines;
A B C D E F G H I J K L
;
proc optnet
data_nodes = NodeSetIn
data_links = LinkSetIn
out_nodes = NodeSetOut;
concomp;
run;
proc print data=NodeSetOut noobs label;
run;
/* Connected Components of a Simple Directed Graph */
data LinkSetIn;
input from $ to $ @@;
datalines;
A B B C B E B F C G
C D D C D H E A E F
F G G F H G H D
;
proc optnet
graph_direction = directed
data_links = LinkSetIn
out_nodes = NodeSetOut;
concomp;
run;
proc print data=NodeSetOut noobs label;
run;
/* CYCLE */
data LinkSetIn;
input from $ to $ @@;
datalines;
A B A E B C C A C D
D E D F E B E C F E
;
proc optnet
graph_direction = directed
data_links = LinkSetIn;
cycle
mode = first_cycle;
run;
%put &_OROPTNET_;
%put &_OROPTNET_CYCLE_;
proc optnet
graph_direction = directed
data_links = LinkSetIn;
cycle
mode = all_cycles;
run;
%put &_OROPTNET_;
%put &_OROPTNET_CYCLE_;
proc optnet
graph_direction = directed
data_links = LinkSetIn;
cycle
out = Cycles
mode = first_cycle;
run;
proc print data=Cycles noobs label;
run;
proc optnet
graph_direction = directed
data_links = LinkSetIn;
cycle
out = Cycles
mode = all_cycles;
run;
proc print data=Cycles noobs label;
run;
/* MINIMUM-COST NETWORK FLOW */
data LinkSetIn;
input from to weight upper;
datalines;
1 4 2 15
2 1 1 10
2 3 0 10
2 6 6 10
3 4 1 5
3 5 4 10
4 7 5 10
5 6 2 20
5 7 7 15
6 8 8 10
7 8 9 15
;
data NodeSetIn;
input node weight;
datalines;
1 10
2 20
4 -5
7 -15
8 -10
;
proc optnet
loglevel = moderate
graph_direction = directed
data_links = LinkSetIn
data_nodes = NodeSetIn
out_links = LinkSetOut;
mincostflow
logfreq = 1;
run;
%put &_OROPTNET_;
%put &_OROPTNET_MCF_;
proc print data=LinkSetOut label ;
run;
data NodeSetIn;
input node weight weight2;
datalines;
1 10 .I
2 20 20
4 .M -5
7 -15 -15
8 -10 -6
;
proc optnet
loglevel = moderate
graph_direction = directed
data_links = LinkSetIn
data_nodes = NodeSetIn
out_links = LinkSetOut;
mincostflow
logfreq = 1;
run;
%put &_OROPTNET_;
%put &_OROPTNET_MCF_;
proc print data=LinkSetOut label ;
run;
/* MINIMUM CUT */
data LinkSetIn;
input from to weight @@;
datalines;
1 2 2 1 5 3 2 3 3 2 5 2 2 6 2
3 4 4 3 7 2 4 7 2 4 8 2 5 6 3
6 7 1 7 8 3
;
proc optnet
loglevel = moderate
out_nodes = NodeSetOut
data_links = LinkSetIn;
mincut
out = MinCut
maxnumcuts = 3;
run;
%put &_OROPTNET_;
%put &_OROPTNET_MINCUT_;
proc print data=NodeSetOut noobs label;
run;
proc print data=MinCut noobs label;
run;
proc print data=MinCut noobs label;
sum weight;
by mincut;
run;
/* MINIMUM SPANNING TREE */
data LinkSetIn;
input from $ to $ weight @@;
datalines;
A B 7 A D 5 B C 8 B D 9 B E 7
C E 5 D E 15 D F 6 E F 8 E G 9
F G 11 H I 1 I J 3 H J 2
;
proc optnet
data_links = LinkSetIn;
minspantree
out = MinSpanForest;
run;
proc print data=MinSpanForest noobs label;
sum weight;
run;
/* SHORTEST PATH */
/* Shortest Paths for All Pairs */
data LinkSetIn;
input from $ to $ weight @@;
datalines;
A B 3 A C 2 A D 6 A E 4 B D 5
B F 5 C E 1 D E 2 D F 1 E F 4
;
proc optnet
data_links = LinkSetIn;
shortpath
out_weights = ShortPathW
out_paths = ShortPathP;
run;
title 'ShortPathP';
proc print data=ShortPathP noobs label;
run;
title 'ShortPathW';
proc print data=ShortPathW noobs label;
run;
proc optnet
data_links = LinkSetIn;
shortpath
paths = longest
out_paths = ShortPathLong;
run;
title 'ShortPathLong';
proc print data=ShortPathLong noobs label;
run;
/* Shortest Paths for a Subset of Source-Sink Pairs */
data NodeSubSetIn;
input node $ source sink;
datalines;
A 1 0
C 1 0
B 0 1
F 0 1
;
proc optnet
data_nodes_sub = NodeSubSetIn
data_links = LinkSetIn;
shortpath
out_paths = ShortPath;
run;
title 'ShortPath';
proc print data=ShortPath noobs label;
run;
/* Shortest Paths for a Subset of Source or Sink Pairs */
data NodeSubSetIn;
input node $ source;
datalines;
B 1
E 1
;
proc optnet
data_nodes_sub = NodeSubSetIn
data_links = LinkSetIn;
shortpath
out_paths = ShortPath;
run;
title 'ShortPath';
proc print data=ShortPath noobs label;
run;
data NodeSubSetIn;
input node $ sink;
datalines;
B 1
E 1
;
proc optnet
data_nodes_sub = NodeSubSetIn
data_links = LinkSetIn;
shortpath
out_paths = ShortPath;
run;
title 'ShortPath';
proc print data=ShortPath noobs label;
run;
/* Shortest Paths for One Source-Sink Pair */
proc optnet
data_links = LinkSetIn;
shortpath
source = C
sink = F
out_paths = ShortPath;
run;
title 'ShortPath';
proc print data=ShortPath noobs label;
run;
data LinkSetIn;
input from $ to $ weight count @@;
datalines;
A B 3 1 A C 2 1 A D 6 1 A E 4 1 B D 5 1
B F 5 1 C E 1 1 D E 2 1 D F 1 1 E F 4 1
;
proc optnet
data_links = LinkSetIn;
shortpath
weight2 = count
out_weights = ShortPathW;
run;
title 'ShortPathW';
proc print data=ShortPathW noobs label;
run;
/* TRANSITIVE CLOSURE */
data LinkSetIn;
input from $ to $ @@;
datalines;
B C B D C B D A D C
;
proc optnet
graph_direction = directed
data_links = LinkSetIn;
transitive_closure
out = TransClosure;
run;
title 'Transitive Closure';
proc print data=TransClosure noobs label;
run;
/* TRAVELING SALESMAN PROBLEM */
data LinkSetIn;
input from $ to $ weight @@;
datalines;
A B 1.0 A C 1.0 A D 1.5 B C 2.0 B D 4.0
B E 3.0 C D 3.0 C F 3.0 C H 4.0 D E 1.5
D F 3.0 D G 4.0 E F 1.0 E G 1.0 F G 2.0
F H 4.0 H I 3.0 I J 1.0 C J 5.0 F J 3.0
F I 1.0 H J 1.0
;
proc optnet
loglevel = moderate
data_links = LinkSetIn
out_nodes = NodeSetOut;
tsp
out = TSPTour;
run;
%put &_OROPTNET_;
%put &_OROPTNET_TSP_;
title 'Traveling Salesman Problem';
proc sort data=NodeSetOut;
by tsp_order;
run;
proc print data=NodeSetOut noobs label;
run;
proc print data=TSPTour noobs label;
sum weight;
run;
/* TRAVELING SALESMAN PROBLEM AND MINIMUM SPANNING TREE */
data LinkSetIn;
input from $ to $ weight @@;
datalines;
A B 1.0 A C 1.0 A D 1.5 B C 2.0 B D 4.0
B E 3.0 C D 3.0 C F 3.0 C H 4.0 D E 1.5
D F 3.0 D G 4.0 E F 1.0 E G 1.0 F G 2.0
F H 4.0 H I 3.0 I J 1.0 C J 5.0 F J 3.0
F I 1.0 H J 1.0
;
proc optnet
loglevel = moderate
data_links = LinkSetIn
out_nodes = NodeSetOut;
mst
out = MST;
tsp
out = TSP;
run;
%put &_OROPTNET_;
%put &_OROPTNET_TSP_;
%put &_OROPTNET_MST_;