aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dk.biks.bachelorizer/dk/biks/bachelorizer/Graph.java28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Graph.java b/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Graph.java
index cebdb0e..2d36d14 100644
--- a/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Graph.java
+++ b/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Graph.java
@@ -249,34 +249,38 @@ public final class Graph extends Storage {
///
/// @param g sets of disjoint choices as a graph
/// @return best path among many random ones
- private static int solveManyTimes(final AbstractGraph g) {
+ private static long[] solveManyTimes(final AbstractGraph g) {
// number higher than total students
- int bestPathCost = Integer.MAX_VALUE;
- for (int i = 0; i < DEMO_ITERATIONS; i++) {
- int cost = solve(g);
- if (cost < bestPathCost) {
+ long[] bestSolution = solve(g);
+ for (int i = 1; i < DEMO_ITERATIONS; i++) {
+ long[] solution = solve(g);
+ if (solution[0] < bestSolution[0]) {
// store shortest path
- bestPathCost = cost;
+ bestSolution = solution;
}
}
- return bestPathCost;
+ return bestSolution;
}
/// find total weight of random path through disjoint choice sets
///
/// @param g sets of disjoint choices as a graph
/// @return total weight of random path
- private static int solve(final AbstractGraph g) {
+ private static long[] solve(final AbstractGraph g) {
+
+ /// parameters for solution
+ long[] solution = new long[] {0};
+
List<Vertex> path = new ArrayList<>(g.vertices());
// order of list contents becomes path order
Collections.shuffle(path);
- int cost = 0;
for (int i = 0; i < path.size() - 1; i++) {
- cost += g.getWeight(path.get(i), path.get(i + 1));
+ solution[0] += g.getWeight(
+ path.get(i), path.get(i + 1));
}
- return cost;
+ return solution;
}
/// Demo function to solve assignment
@@ -317,6 +321,6 @@ public final class Graph extends Storage {
System.out.print(
"\n\nSolution with disjoint choices found: ");
System.out.println(
- solveManyTimes(h));
+ solveManyTimes(h)[0]);
}
}