All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.barrybecker4.discreteoptimization.apps.DemoGraphApp.scala Maven / Gradle / Ivy

The newest version!
package com.barrybecker4.discreteoptimization.apps

import com.barrybecker4.discreteoptimization.common.graph.Graph
import com.barrybecker4.discreteoptimization.common.graph.algorithms.kshortestpaths.YensAlgorithm
import com.barrybecker4.discreteoptimization.common.graph.directed.{DirectedEdge, DirectedGraph}

object DemoGraphApp extends App {

  val graph = createGraph()
  val numShortestPaths = 2
  val kshortestPaths = YensAlgorithm(graph).findKShortestPaths(0, 4, numShortestPaths)
  println(s"The $numShortestPaths found were:\n" + kshortestPaths)

  private def createGraph(): DirectedGraph = {
    val edges = IndexedSeq(
      DirectedEdge(0, 2, 2.2),
      DirectedEdge(0, 3, 2.2),
      DirectedEdge(2, 1, 2.2),
      DirectedEdge(3, 1, 2.2),
      DirectedEdge(1, 4, 2.2),
      DirectedEdge(2, 4, 2.2),
      DirectedEdge(2, 4, 20.8),
      DirectedEdge(4, 2, 1.2),
      DirectedEdge(1, 0, 1.1),
    )
    DirectedGraph(5, edges)
  }

}







© 2015 - 2025 Weber Informatics LLC | Privacy Policy