Skip to content
Snippets Groups Projects
Commit 6ef54954 authored by Paul A. Rubin's avatar Paul A. Rubin
Browse files

Renamed the greedy construction heuristic.

parent ecbe50c4
No related branches found
No related tags found
No related merge requests found
...@@ -8,7 +8,8 @@ import java.util.List; ...@@ -8,7 +8,8 @@ import java.util.List;
import xmtrclusters.Problem; import xmtrclusters.Problem;
/** /**
* Greedy implements a greedy heuristic for the clustering problem. * GreedyConstruction implements a greedy construction heuristic for the
* clustering problem.
* *
* Initially, each transmitter is a cluster unto itself. In each iteration, * Initially, each transmitter is a cluster unto itself. In each iteration,
* all legal merges of a pair of clusters are tested, and the one with maximum * all legal merges of a pair of clusters are tested, and the one with maximum
...@@ -23,7 +24,7 @@ import xmtrclusters.Problem; ...@@ -23,7 +24,7 @@ import xmtrclusters.Problem;
record Merger(int first, int second, double change) { } record Merger(int first, int second, double change) { }
public final class Greedy { public final class GreedyConstruction {
private final List<Collection<Integer>> clusters; // list of clusters private final List<Collection<Integer>> clusters; // list of clusters
private final Problem problem; // problem to solve private final Problem problem; // problem to solve
private final int maxSize; // maximum problem size private final int maxSize; // maximum problem size
...@@ -33,7 +34,7 @@ public final class Greedy { ...@@ -33,7 +34,7 @@ public final class Greedy {
* Constructs the heuristic instance and solves it. * Constructs the heuristic instance and solves it.
* @param prob the problem to solve * @param prob the problem to solve
*/ */
public Greedy(final Problem prob) { public GreedyConstruction(final Problem prob) {
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
problem = prob; problem = prob;
maxSize = prob.getMaxSize(); // max cluster size maxSize = prob.getMaxSize(); // max cluster size
...@@ -75,7 +76,8 @@ public final class Greedy { ...@@ -75,7 +76,8 @@ public final class Greedy {
} }
} }
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.println("\nThe greedy heuristic ran for " + time + " ms."); System.out.println("\nThe greedy construction heuristic ran for "
+ time + " ms.");
} }
/** /**
......
...@@ -2,7 +2,7 @@ package xmtrclusters; ...@@ -2,7 +2,7 @@ package xmtrclusters;
import ilog.concert.IloException; import ilog.concert.IloException;
import java.util.Collection; import java.util.Collection;
import solvers.Greedy; import solvers.GreedyConstruction;
import solvers.MIPModel; import solvers.MIPModel;
import solvers.MIPModel2; import solvers.MIPModel2;
...@@ -33,10 +33,10 @@ public final class XmtrClusters { ...@@ -33,10 +33,10 @@ public final class XmtrClusters {
int nU = 60; // # of users int nU = 60; // # of users
int maxC = 7; // maximum number of clusters int maxC = 7; // maximum number of clusters
int maxS = 5; // maximum cluster size int maxS = 5; // maximum cluster size
Problem prob = new Problem(nT, nU, maxC, maxS, 456); Problem prob = new Problem(nT, nU, maxC, maxS, 1234);
// Try the greedy heuristic. // Try the greedy heuristic.
Greedy greedy = new Greedy(prob); GreedyConstruction greedy = new GreedyConstruction(prob);
Collection<Collection<Integer>> g = greedy.getSolution(); Collection<Collection<Integer>> g = greedy.getSolution();
if (g.isEmpty()) { if (g.isEmpty()) {
System.out.println("\nThe greedy heuristic failed."); System.out.println("\nThe greedy heuristic failed.");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment