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

Reordered methods.

parent c1947126
No related branches found
No related tags found
No related merge requests found
...@@ -83,30 +83,6 @@ public final class Problem { ...@@ -83,30 +83,6 @@ public final class Problem {
} }
} }
/**
* Computes the service quality for a single user.
* @param user the index of the user
* @param cluster the indices of all transmitters in the same cluster as the
* user
* @return the service quality for the user
*/
public double userQuality(final int user, final Collection<Integer> cluster) {
// Make sure at least one transmitter is not in the cluster (to avoid
// division by zero).
if (cluster.size() == nTrans) {
throw new IllegalArgumentException("Cannot have all transmitters"
+ " in one cluster.");
}
// The numerator is the sum of weights for all transmitters in the cluster.
double num = cluster.stream().mapToDouble(t -> weight[t][user]).sum();
// The denominator is the sum of weights for all transmitters not in
// the cluster.
HashSet<Integer> out = new HashSet<>(allTransmitters);
out.removeAll(cluster);
double denom = out.stream().mapToDouble(t -> weight[t][user]).sum();
return num / denom;
}
/** /**
* Generates a summary of a solution. * Generates a summary of a solution.
* @param solution the solution (a collection of clusters of transmitters) * @param solution the solution (a collection of clusters of transmitters)
...@@ -190,12 +166,27 @@ public final class Problem { ...@@ -190,12 +166,27 @@ public final class Problem {
} }
/** /**
* Computes the total quality of a proposed solution. * Computes the service quality for a single user.
* @param clusters a collection of clusters * @param user the index of the user
* @return the total user quality for that solution * @param cluster the indices of all transmitters in the same cluster as the
* user
* @return the service quality for the user
*/ */
public double totalQuality(final Collection<Collection<Integer>> clusters) { public double userQuality(final int user, final Collection<Integer> cluster) {
return clusters.stream().mapToDouble(c -> clusterQuality(c)).sum(); // Make sure at least one transmitter is not in the cluster (to avoid
// division by zero).
if (cluster.size() == nTrans) {
throw new IllegalArgumentException("Cannot have all transmitters"
+ " in one cluster.");
}
// The numerator is the sum of weights for all transmitters in the cluster.
double num = cluster.stream().mapToDouble(t -> weight[t][user]).sum();
// The denominator is the sum of weights for all transmitters not in
// the cluster.
HashSet<Integer> out = new HashSet<>(allTransmitters);
out.removeAll(cluster);
double denom = out.stream().mapToDouble(t -> weight[t][user]).sum();
return num / denom;
} }
/** /**
...@@ -210,4 +201,13 @@ public final class Problem { ...@@ -210,4 +201,13 @@ public final class Problem {
// Total their quality values. // Total their quality values.
return list.stream().mapToDouble(u -> userQuality(u, cluster)).sum(); return list.stream().mapToDouble(u -> userQuality(u, cluster)).sum();
} }
/**
* Computes the total quality of a proposed solution.
* @param clusters a collection of clusters
* @return the total user quality for that solution
*/
public double totalQuality(final Collection<Collection<Integer>> clusters) {
return clusters.stream().mapToDouble(c -> clusterQuality(c)).sum();
}
} }
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