SlideShare a Scribd company logo
Prepared by Volkan OBAN
optrees package in R
Finds optimal trees in weighted graphs. In particular, this package provid
es solving tools for minimum costspanning tree problems,minimum cost
arborescenceproblems,shortestpath tree problems and minimum cut tr
ee problem.
Examples:
Minimum Spanning Tree
>nodes <- 1:4
> arcs <- matrix(c(1,2,2, 1,3,15, 1,4,3, 2,3,1, 2,4,9, 3,4,1),
+ ncol = 3, byrow = TRUE)
> # Minimum cost spanning tree with several algorithms
> getMinimumSpanningTree(nodes, arcs, algorithm = "Prim")
Minimum Cost Spanning Tree
Algorithm: Prim
Stages: 3 | Time: 0
------------------------------
ept1 ept2 weight
1 2 2
2 3 1
3 4 1
------------------------------
Total = 4
> getMinimumSpanningTree(nodes, arcs, algorithm = "Kruskal")
Minimum Cost Spanning Tree
Algorithm: Kruskal
Stages: 3 | Time: 0
------------------------------
ept1 ept2 weight
2 3 1
3 4 1
1 2 2
------------------------------
Total = 4
> getMinimumSpanningTree(nodes, arcs, algorithm = "Boruvka")
Minimum Cost Spanning Tree
Algorithm: Boruvka
Stages: 1 | Time: 0
------------------------------
ept1 ept2 weight
1 2 2
2 3 1
3 4 1
------------------------------
Total = 4
Shortest Path Tree:
> nodes <- 1:5
> arcs <- matrix(c(1,2,2, 1,3,2, 1,4,3, 2,5,5, 3,2,4, 3,5,3, 4,3,1, 4,5,0),
+ ncol = 3, byrow = TRUE)
> # Shortest path tree
> getShortestPathTree(nodes, arcs, algorithm = "Dijkstra", directed=FALSE)
Shortest path tree
Algorithm: Dijkstra
Stages: 4 | Time: 0
------------------------------
ept1 ept2 weight
1 2 2
1 3 2
1 4 3
4 5 0
------------------------------
Total = 7
Distances from source:
------------------------------
source node distance
1 2 2
1 3 2
1 4 3
1 5 3
------------------------------
> getShortestPathTree(nodes, arcs, algorithm = "Bellman-Ford", directed=FAL
SE)
Shortest path tree
Algorithm: Bellman-Ford
Stages: 4 | Time: 0
------------------------------
ept1 ept2 weight
1 2 2
1 3 2
1 4 3
4 5 0
------------------------------
Total = 7
Distances from source:
------------------------------
source node distance
1 2 2
1 3 2
1 4 3
1 5 3
------------------------------
> # Graph with negative weights
> nodes <- 1:5
> arcs <- matrix(c(1,2,6, 1,3,7, 2,3,8, 2,4,5, 2,5,-4, 3,4,-3, 3,5,9, 4,2,-
2,
+ 5,1,2, 5,4,7), ncol = 3, byrow = TRUE)
> # Shortest path tree
> getShortestPathTree(nodes, arcs, algorithm = "Bellman-Ford", directed=TRU
E)
Shortest path tree
Algorithm: Bellman-Ford
Stages: 4 | Time: 0.09
------------------------------
head tail weight
1 3 7
2 5 -4
3 4 -3
4 2 -2
------------------------------
Total = -2
Distances from source:
------------------------------
source node distance
1 2 2
1 3 7
1 4 4
1 5 -2
------------------------------
Maximum flow:
> # Graph
> nodes <- 1:6
> arcs <- matrix(c(1,2,1, 1,3,7, 2,3,1, 2,4,3, 2,5,2, 3,5,4, 4,5,1, 4,6,6,
+ 5,6,2), byrow = TRUE, ncol = 3)
> # Maximum flow with Ford-Fulkerson algorithm
> maxFlowFordFulkerson(nodes, arcs, source.node = 2, sink.node = 6)
$s.cut
[1] 2 3 1 5
$t.cut
[1] 4 6
$max.flow
[1] 6

More Related Content

PDF
Org Beamer
PDF
Variations of PostgreSQL Replication
 
PPTX
Tems 8 Basic steps for beginners
PDF
benpresentation_django
PPTX
routing algorithm
TXT
Balanceo con 2 wan
PDF
Report AdvOpticalComm - Pietro Santoro -
PDF
NetSim Technology Library- Propagation models
Org Beamer
Variations of PostgreSQL Replication
 
Tems 8 Basic steps for beginners
benpresentation_django
routing algorithm
Balanceo con 2 wan
Report AdvOpticalComm - Pietro Santoro -
NetSim Technology Library- Propagation models

What's hot (8)

PPTX
Modul mengamankan jaringan dhcp server menggunakan arp reply only menggunakan...
PPTX
Modul dhcp server menggunakan mikrotik os
TXT
Remote Pattern
PDF
EE402B Radio Systems and Personal Communication Networks notes
DOC
Ramco C Question Paper 2003
TXT
Backup and restore router configuration
PDF
Vpn addind technique
PPTX
Wired Network Simulation in NS2 Research Guidance
Modul mengamankan jaringan dhcp server menggunakan arp reply only menggunakan...
Modul dhcp server menggunakan mikrotik os
Remote Pattern
EE402B Radio Systems and Personal Communication Networks notes
Ramco C Question Paper 2003
Backup and restore router configuration
Vpn addind technique
Wired Network Simulation in NS2 Research Guidance
Ad

Similar to "optrees" package in R and examples.(optrees:finds optimal trees in weighted graphs) (20)

PDF
lec03 lec03 lec03 lec03 lec03 lec03 lec03
PPTX
Greedy technique - Algorithm design techniques using data structures
PPTX
My presentation minimum spanning tree
PPT
Greedy Approach in Design Analysis and Algorithms
PPTX
7. Spanning trees
PPTX
Ram minimum spanning tree
PPTX
DM Min SPan Tree Minimum spanning tree .pptx
PPTX
11L_2024_DSCS_EN_Trees2_Prim_Kraskal.pptx
PPTX
Data Structures, Graphs
PPTX
PPTX
Data structure and algorithm
PPT
algorthm analysis from computer scince.ppt
PPTX
Spanning Tree in data structure and .pptx
PPTX
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
PPT
Weighted graphs
PPTX
Optimisation random graph presentation
PDF
Skiena algorithm 2007 lecture13 minimum spanning trees
PPTX
Graph Algorithms
lec03 lec03 lec03 lec03 lec03 lec03 lec03
Greedy technique - Algorithm design techniques using data structures
My presentation minimum spanning tree
Greedy Approach in Design Analysis and Algorithms
7. Spanning trees
Ram minimum spanning tree
DM Min SPan Tree Minimum spanning tree .pptx
11L_2024_DSCS_EN_Trees2_Prim_Kraskal.pptx
Data Structures, Graphs
Data structure and algorithm
algorthm analysis from computer scince.ppt
Spanning Tree in data structure and .pptx
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
Weighted graphs
Optimisation random graph presentation
Skiena algorithm 2007 lecture13 minimum spanning trees
Graph Algorithms
Ad

More from Dr. Volkan OBAN (20)

PDF
Conference Paper:IMAGE PROCESSING AND OBJECT DETECTION APPLICATION: INSURANCE...
PDF
Covid19py Python Package - Example
PDF
Object detection with Python
PDF
Python - Rastgele Orman(Random Forest) Parametreleri
DOCX
Linear Programming wi̇th R - Examples
DOCX
k-means Clustering in Python
DOCX
Naive Bayes Example using R
DOCX
R forecasting Example
DOCX
k-means Clustering and Custergram with R
PDF
Data Science and its Relationship to Big Data and Data-Driven Decision Making
DOCX
Data Visualization with R.ggplot2 and its extensions examples.
PDF
Scikit-learn Cheatsheet-Python
PDF
Python Pandas for Data Science cheatsheet
PDF
Pandas,scipy,numpy cheatsheet
PPTX
ReporteRs package in R. forming powerpoint documents-an example
PPTX
ReporteRs package in R. forming powerpoint documents-an example
DOCX
R-ggplot2 package Examples
DOCX
R Machine Learning packages( generally used)
DOCX
treemap package in R and examples.
DOCX
Mosaic plot in R.
Conference Paper:IMAGE PROCESSING AND OBJECT DETECTION APPLICATION: INSURANCE...
Covid19py Python Package - Example
Object detection with Python
Python - Rastgele Orman(Random Forest) Parametreleri
Linear Programming wi̇th R - Examples
k-means Clustering in Python
Naive Bayes Example using R
R forecasting Example
k-means Clustering and Custergram with R
Data Science and its Relationship to Big Data and Data-Driven Decision Making
Data Visualization with R.ggplot2 and its extensions examples.
Scikit-learn Cheatsheet-Python
Python Pandas for Data Science cheatsheet
Pandas,scipy,numpy cheatsheet
ReporteRs package in R. forming powerpoint documents-an example
ReporteRs package in R. forming powerpoint documents-an example
R-ggplot2 package Examples
R Machine Learning packages( generally used)
treemap package in R and examples.
Mosaic plot in R.

Recently uploaded (20)

PPT
ISS -ESG Data flows What is ESG and HowHow
PPTX
Microsoft-Fabric-Unifying-Analytics-for-the-Modern-Enterprise Solution.pptx
PPTX
Introduction to Knowledge Engineering Part 1
PPTX
Acceptance and paychological effects of mandatory extra coach I classes.pptx
PPT
Miokarditis (Inflamasi pada Otot Jantung)
PPTX
iec ppt-1 pptx icmr ppt on rehabilitation.pptx
PPTX
Business Ppt On Nestle.pptx huunnnhhgfvu
PPTX
01_intro xxxxxxxxxxfffffffffffaaaaaaaaaaafg
PPTX
Introduction to Firewall Analytics - Interfirewall and Transfirewall.pptx
PDF
Fluorescence-microscope_Botany_detailed content
PPTX
Introduction to machine learning and Linear Models
PPTX
Introduction-to-Cloud-ComputingFinal.pptx
PDF
168300704-gasification-ppt.pdfhghhhsjsjhsuxush
PPTX
oil_refinery_comprehensive_20250804084928 (1).pptx
PPTX
climate analysis of Dhaka ,Banglades.pptx
PPT
Reliability_Chapter_ presentation 1221.5784
PDF
Foundation of Data Science unit number two notes
PPTX
The THESIS FINAL-DEFENSE-PRESENTATION.pptx
PDF
Galatica Smart Energy Infrastructure Startup Pitch Deck
PPTX
1_Introduction to advance data techniques.pptx
ISS -ESG Data flows What is ESG and HowHow
Microsoft-Fabric-Unifying-Analytics-for-the-Modern-Enterprise Solution.pptx
Introduction to Knowledge Engineering Part 1
Acceptance and paychological effects of mandatory extra coach I classes.pptx
Miokarditis (Inflamasi pada Otot Jantung)
iec ppt-1 pptx icmr ppt on rehabilitation.pptx
Business Ppt On Nestle.pptx huunnnhhgfvu
01_intro xxxxxxxxxxfffffffffffaaaaaaaaaaafg
Introduction to Firewall Analytics - Interfirewall and Transfirewall.pptx
Fluorescence-microscope_Botany_detailed content
Introduction to machine learning and Linear Models
Introduction-to-Cloud-ComputingFinal.pptx
168300704-gasification-ppt.pdfhghhhsjsjhsuxush
oil_refinery_comprehensive_20250804084928 (1).pptx
climate analysis of Dhaka ,Banglades.pptx
Reliability_Chapter_ presentation 1221.5784
Foundation of Data Science unit number two notes
The THESIS FINAL-DEFENSE-PRESENTATION.pptx
Galatica Smart Energy Infrastructure Startup Pitch Deck
1_Introduction to advance data techniques.pptx

"optrees" package in R and examples.(optrees:finds optimal trees in weighted graphs)

  • 1. Prepared by Volkan OBAN optrees package in R Finds optimal trees in weighted graphs. In particular, this package provid es solving tools for minimum costspanning tree problems,minimum cost arborescenceproblems,shortestpath tree problems and minimum cut tr ee problem. Examples: Minimum Spanning Tree >nodes <- 1:4 > arcs <- matrix(c(1,2,2, 1,3,15, 1,4,3, 2,3,1, 2,4,9, 3,4,1), + ncol = 3, byrow = TRUE) > # Minimum cost spanning tree with several algorithms > getMinimumSpanningTree(nodes, arcs, algorithm = "Prim") Minimum Cost Spanning Tree Algorithm: Prim Stages: 3 | Time: 0 ------------------------------ ept1 ept2 weight 1 2 2 2 3 1 3 4 1 ------------------------------ Total = 4 > getMinimumSpanningTree(nodes, arcs, algorithm = "Kruskal") Minimum Cost Spanning Tree Algorithm: Kruskal Stages: 3 | Time: 0
  • 2. ------------------------------ ept1 ept2 weight 2 3 1 3 4 1 1 2 2 ------------------------------ Total = 4 > getMinimumSpanningTree(nodes, arcs, algorithm = "Boruvka") Minimum Cost Spanning Tree Algorithm: Boruvka Stages: 1 | Time: 0 ------------------------------ ept1 ept2 weight 1 2 2 2 3 1 3 4 1 ------------------------------ Total = 4 Shortest Path Tree: > nodes <- 1:5 > arcs <- matrix(c(1,2,2, 1,3,2, 1,4,3, 2,5,5, 3,2,4, 3,5,3, 4,3,1, 4,5,0), + ncol = 3, byrow = TRUE) > # Shortest path tree > getShortestPathTree(nodes, arcs, algorithm = "Dijkstra", directed=FALSE) Shortest path tree Algorithm: Dijkstra Stages: 4 | Time: 0 ------------------------------ ept1 ept2 weight 1 2 2 1 3 2 1 4 3 4 5 0 ------------------------------ Total = 7 Distances from source: ------------------------------ source node distance 1 2 2 1 3 2 1 4 3 1 5 3 ------------------------------ > getShortestPathTree(nodes, arcs, algorithm = "Bellman-Ford", directed=FAL SE) Shortest path tree
  • 3. Algorithm: Bellman-Ford Stages: 4 | Time: 0 ------------------------------ ept1 ept2 weight 1 2 2 1 3 2 1 4 3 4 5 0 ------------------------------ Total = 7 Distances from source: ------------------------------ source node distance 1 2 2 1 3 2 1 4 3 1 5 3 ------------------------------ > # Graph with negative weights > nodes <- 1:5 > arcs <- matrix(c(1,2,6, 1,3,7, 2,3,8, 2,4,5, 2,5,-4, 3,4,-3, 3,5,9, 4,2,- 2, + 5,1,2, 5,4,7), ncol = 3, byrow = TRUE) > # Shortest path tree > getShortestPathTree(nodes, arcs, algorithm = "Bellman-Ford", directed=TRU E) Shortest path tree Algorithm: Bellman-Ford Stages: 4 | Time: 0.09 ------------------------------ head tail weight 1 3 7 2 5 -4 3 4 -3 4 2 -2 ------------------------------ Total = -2 Distances from source: ------------------------------ source node distance 1 2 2 1 3 7 1 4 4 1 5 -2 ------------------------------ Maximum flow: > # Graph > nodes <- 1:6 > arcs <- matrix(c(1,2,1, 1,3,7, 2,3,1, 2,4,3, 2,5,2, 3,5,4, 4,5,1, 4,6,6, + 5,6,2), byrow = TRUE, ncol = 3) > # Maximum flow with Ford-Fulkerson algorithm
  • 4. > maxFlowFordFulkerson(nodes, arcs, source.node = 2, sink.node = 6) $s.cut [1] 2 3 1 5 $t.cut [1] 4 6 $max.flow [1] 6