1
1
package com.tripletres.platformscience.domain.algorithm
2
2
3
3
import com.tripletres.platformscience.domain.ShipmentDriverAssignation.SuitabilityScore
4
+ import com.tripletres.platformscience.domain.algorithm.BranchAndBoundAlgorithm.Node
4
5
import com.tripletres.platformscience.domain.model.Driver
5
6
import com.tripletres.platformscience.domain.model.Shipment
6
7
@@ -33,13 +34,14 @@ import com.tripletres.platformscience.domain.model.Shipment
33
34
*/
34
35
class BranchAndBoundAlgorithm : IAssignationAlgorithm {
35
36
37
+ private var n = 0
38
+
36
39
override fun getBestMatching (input : MutableList <MutableList <SuitabilityScore >>): List <Driver > {
40
+ n = input.size
37
41
return execute(matrix = input)
38
42
}
39
43
40
- fun execute (matrix : MutableList <MutableList <SuitabilityScore >>): List <Driver > {
41
- val n = matrix[0 ].size
42
-
44
+ private fun execute (matrix : MutableList <MutableList <SuitabilityScore >>): List <Driver > {
43
45
// Priority queue for nodes that are "live"
44
46
val priorityQueue = mutableListOf<Node >()
45
47
@@ -81,7 +83,7 @@ class BranchAndBoundAlgorithm : IAssignationAlgorithm {
81
83
82
84
// Calculate lower ss (that includes the path ss)
83
85
child.ss = child.pathSS +
84
- getLowestSSAfterDriverAssignedShipment(matrix, i, j, child.assigned)
86
+ getLowestSSAfterDriverAssignedShipment(matrix, i, child.assigned)
85
87
child.driverIndex = i
86
88
// Add child node to queue
87
89
priorityQueue.add(child)
@@ -94,14 +96,12 @@ class BranchAndBoundAlgorithm : IAssignationAlgorithm {
94
96
return getBuildNodes(minOut)
95
97
}
96
98
97
- fun getLowestSSAfterDriverAssignedShipment (
99
+ private fun getLowestSSAfterDriverAssignedShipment (
98
100
matrix : MutableList <MutableList <SuitabilityScore >>,
99
101
driver : Int ,
100
- shipment : Int ,
101
102
assigned : HashMap <Shipment , Boolean >,
102
103
): Float {
103
104
var cost = 0f ;
104
- val n = matrix[driver].size
105
105
106
106
// Store available shipment
107
107
val available = matrix[driver].associate { it.shipment to true }
0 commit comments