本文整理汇总了Java中org.uma.jmetal.solution.Solution类的典型用法代码示例。如果您正苦于以下问题:Java Solution类的具体用法?Java Solution怎么用?Java Solution使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Solution类属于org.uma.jmetal.solution包,在下文中一共展示了Solution类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldExecuteReturnZeroIfTheFrontsContainOnePointWhichIsTheSame
import org.uma.jmetal.solution.Solution; //导入依赖的package包/类
@Test
public void shouldExecuteReturnZeroIfTheFrontsContainOnePointWhichIsTheSame() {
int numberOfPoints = 1 ;
int numberOfDimensions = 3 ;
Front frontA = new ArrayFront(numberOfPoints, numberOfDimensions);
Front frontB = new ArrayFront(numberOfPoints, numberOfDimensions);
Point point1 = new ArrayPoint(numberOfDimensions) ;
point1.setDimensionValue(0, 10.0);
point1.setDimensionValue(1, 12.0);
point1.setDimensionValue(2, -1.0);
frontA.setPoint(0, point1);
frontB.setPoint(0, point1);
Pair<Double, Double> result = setCoverage.evaluate(new ImmutablePair<List<? extends Solution<?>>, List<? extends Solution<?>>>(
FrontUtils.convertFrontToSolutionList(frontA),
FrontUtils.convertFrontToSolutionList(frontB))) ;
assertEquals(0.0, result.getLeft(), EPSILON);
}
示例2: shouldTwoPerpendicularPointsHaveADistanceOfZero
import org.uma.jmetal.solution.Solution; //导入依赖的package包/类
@Test
public void shouldTwoPerpendicularPointsHaveADistanceOfZero() {
Solution<?> idealPoint = mock(Solution.class) ;
when(idealPoint.getObjective(0)).thenReturn(0.0) ;
when(idealPoint.getObjective(1)).thenReturn(0.0) ;
when(idealPoint.getNumberOfObjectives()).thenReturn(3) ;
Solution<?> point1 = mock(Solution.class) ;
when(point1.getObjective(0)).thenReturn(0.0) ;
when(point1.getObjective(1)).thenReturn(1.0) ;
when(point1.getNumberOfObjectives()).thenReturn(3) ;
Solution<?> point2 = mock(Solution.class) ;
when(point2.getObjective(0)).thenReturn(1.0) ;
when(point2.getObjective(1)).thenReturn(0.0) ;
when(point2.getNumberOfObjectives()).thenReturn(3) ;
CosineDistanceBetweenSolutionsInObjectiveSpace<Solution<?>> distance =
new CosineDistanceBetweenSolutionsInObjectiveSpace<Solution<?>>(idealPoint) ;
double receivedValue = distance.getDistance(point1, point2) ;
assertEquals(0.0, receivedValue, EPSILON) ;
}
示例3: printObjectivesToFile
import org.uma.jmetal.solution.Solution; //导入依赖的package包/类
public void printObjectivesToFile(FileOutputContext context, List<? extends Solution<?>> solutionList) {
BufferedWriter bufferedWriter = context.getFileWriter();
try {
if (solutionList.size() > 0) {
int numberOfObjectives = solutionList.get(0).getNumberOfObjectives();
for (int i = 0; i < solutionList.size(); i++) {
for (int j = 0; j < numberOfObjectives; j++) {
bufferedWriter.write(solutionList.get(i).getObjective(j) + context.getSeparator());
}
bufferedWriter.newLine();
}
}
bufferedWriter.close();
} catch (IOException e) {
throw new JMetalException("Error printing objecives to file: ", e);
}
}
示例4: getNormalizedFront
import org.uma.jmetal.solution.Solution; //导入依赖的package包/类
/**
* This method receives a list of non-dominated solutions and maximum and minimum values of the
* objectives, and returns a the normalized set of solutions.
*
* @param solutionList A list of non-dominated solutions
* @param maximumValue The maximum values of the objectives
* @param minimumValue The minimum values of the objectives
* @return the normalized list of non-dominated solutions
*/
public static List<Solution<?>> getNormalizedFront(List<Solution<?>> solutionList,
List<Double> maximumValue,
List<Double> minimumValue) {
List<Solution<?>> normalizedSolutionSet = new ArrayList<>(solutionList.size()) ;
int numberOfObjectives = solutionList.get(0).getNumberOfObjectives() ;
for (int i = 0; i < solutionList.size(); i++) {
Solution<?> solution = solutionList.get(i).copy() ;
for (int j = 0; j < numberOfObjectives; j++) {
double normalizedValue = (solutionList.get(i).getObjective(j) - minimumValue.get(j)) /
(maximumValue.get(j) - minimumValue.get(j));
solution.setObjective(j, normalizedValue);
}
}
return normalizedSolutionSet;
}
示例5: getInvertedFront
import org.uma.jmetal.solution.Solution; //导入依赖的package包/类
/**
* This method receives a normalized list of non-dominated solutions and return the inverted one.
* This operation is needed for minimization problem
*
* @param solutionSet The front to invert
* @return The inverted front
*/
@SuppressWarnings("unchecked")
public static <S extends Solution<?>> List<S> getInvertedFront(List<S> solutionSet) {
List<S> invertedFront = new ArrayList<>(solutionSet.size()) ;
int numberOfObjectives = solutionSet.get(0).getNumberOfObjectives() ;
for (int i = 0; i < solutionSet.size(); i++) {
invertedFront.add(i, (S) solutionSet.get(i).copy()) ;
for (int j = 0; j < numberOfObjectives; j++) {
if (solutionSet.get(i).getObjective(j) <= 1.0 &&
solutionSet.get(i).getObjective(j) >= 0.0) {
invertedFront.get(i).setObjective(j, 1.0 - solutionSet.get(i).getObjective(j));
} else if (solutionSet.get(i).getObjective(j) > 1.0) {
invertedFront.get(i).setObjective(j, 0.0);
} else if (solutionSet.get(i).getObjective(j) < 0.0) {
invertedFront.get(i).setObjective(j, 1.0);
}
}
}
return invertedFront;
}
示例6: ArrayFront
import org.uma.jmetal.solution.Solution; //导入依赖的package包/类
/** Constructor */
public ArrayFront(List<? extends Solution<?>> solutionList) {
if (solutionList == null) {
throw new JMetalException("The list of solutions is null") ;
} else if (solutionList.size() == 0) {
throw new JMetalException("The list of solutions is empty") ;
}
numberOfPoints = solutionList.size();
pointDimensions = solutionList.get(0).getNumberOfObjectives() ;
points = new Point[numberOfPoints] ;
points = new Point[numberOfPoints];
for (int i = 0; i < numberOfPoints; i++) {
Point point = new ArrayPoint(pointDimensions) ;
for (int j = 0; j < pointDimensions; j++) {
point.setDimensionValue(j, solutionList.get(i).getObjective(j));
}
points[i] = point;
}
}
示例7: update
import org.uma.jmetal.solution.Solution; //导入依赖的package包/类
@Override
public void update(Solution<?> solution) {
if (solution == null) {
throw new JMetalException("The solution is null") ;
} else if (solution.getNumberOfObjectives() != this.getNumberOfObjectives()) {
throw new JMetalException("The number of objectives of the solution ("
+ solution.getNumberOfObjectives()
+ ") "
+ "is different to the size of the reference point("
+ this.getNumberOfObjectives()
+ ")"
);
}
for (int i = 0; i < this.getNumberOfObjectives(); i++) {
if (this.getObjective(i) < solution.getObjective(i)) {
this.setObjective(i, solution.getObjective(i));
}
}
}
示例8: run
import org.uma.jmetal.solution.Solution; //导入依赖的package包/类
@Override
public void run() throws IOException {
String rDirectoryName = experiment.getExperimentBaseDirectory() + "/" + DEFAULT_R_DIRECTORY;
File rOutput;
rOutput = new File(rDirectoryName);
if (!rOutput.exists()) {
new File(rDirectoryName).mkdirs();
System.out.println("Creating " + rDirectoryName + " directory");
}
for (GenericIndicator<? extends Solution<?>> indicator : experiment.getIndicatorList()) {
String rFileName = rDirectoryName + "/" + indicator.getName() + ".Wilcoxon" + ".R";
String latexFileName = rDirectoryName + "/" + indicator.getName() + ".Wilcoxon" + ".tex";
printHeaderLatexCommands(rFileName, latexFileName);
printTableHeader(indicator, rFileName, latexFileName);
printLines(indicator, rFileName, latexFileName);
printTableTail(rFileName, latexFileName);
printEndLatexCommands(rFileName, latexFileName);
printGenerateMainScript(indicator, rFileName, latexFileName) ;
}
}
示例9: loadFront
import org.uma.jmetal.solution.Solution; //导入依赖的package包/类
private Front loadFront(List<Solution<?>> solutionSet, int notLoadingIndex) {
int numberOfPoints ;
if (notLoadingIndex >= 0 && notLoadingIndex < solutionSet.size()) {
numberOfPoints = solutionSet.size() - 1;
} else {
numberOfPoints = solutionSet.size();
}
int dimensions = solutionSet.get(0).getNumberOfObjectives();
Front front = new WfgHypervolumeFront(numberOfPoints, dimensions) ;
int index = 0;
for (int i = 0; i < solutionSet.size(); i++) {
if (i != notLoadingIndex) {
Point point = new ArrayPoint(dimensions) ;
for (int j = 0; j < dimensions; j++) {
point.setDimensionValue(j, solutionSet.get(i).getObjective(j));
}
front.setPoint(index++, point);
}
}
return front ;
}
示例10: evaluate
import org.uma.jmetal.solution.Solution; //导入依赖的package包/类
/**
* Calculates the set coverage of set1 over set2
* @param set1
* @param set2
* @return The value of the set coverage
*/
public double evaluate(List<? extends Solution<?>> set1, List<? extends Solution<?>> set2) {
double result ;
int sum = 0 ;
if (set2.size()==0) {
if (set1.size()==0) {
result = 0.0 ;
} else {
result = 1.0 ;
}
} else {
for (Solution<?> solution : set2) {
if (SolutionListUtils.isSolutionDominatedBySolutionList(solution, set1)) {
sum++;
}
}
result = (double)sum/set2.size() ;
}
return result ;
}
示例11: shouldConstructFromASolutionReturnTheCorrectPoint
import org.uma.jmetal.solution.Solution; //导入依赖的package包/类
@Test
public void shouldConstructFromASolutionReturnTheCorrectPoint() {
Solution<?> solution = Mockito.mock(Solution.class) ;
Mockito.when(solution.getNumberOfObjectives()).thenReturn(3) ;
Mockito.when(solution.getObjective(0)).thenReturn(0.2) ;
Mockito.when(solution.getObjective(1)).thenReturn(234.23) ;
Mockito.when(solution.getObjective(2)).thenReturn(-234.2356) ;
Point point = new ArrayPoint(solution) ;
double[] expectedArray = {0.2, 234.23, -234.2356} ;
double[] pointDimensions = (double[])ReflectionTestUtils.getField(point, "point");
assertArrayEquals(expectedArray, pointDimensions, EPSILON);
Mockito.verify(solution).getNumberOfObjectives() ;
Mockito.verify(solution, Mockito.times(3)).getObjective(Mockito.anyInt());
}
示例12: shouldGetNeighborsWorkProperlyCaseA
import org.uma.jmetal.solution.Solution; //导入依赖的package包/类
/**
* Case A: The solution list has two solutions and the neighbor size is 1
*/
@Test
public void shouldGetNeighborsWorkProperlyCaseA() {
Solution<?> point1 = mock(Solution.class) ;
when(point1.getObjective(0)).thenReturn(0.0) ;
when(point1.getObjective(1)).thenReturn(0.0) ;
Solution<?> point2 = mock(Solution.class) ;
when(point2.getObjective(0)).thenReturn(1.0) ;
when(point2.getObjective(1)).thenReturn(1.0) ;
List<Solution<?>> solutionList = Arrays.asList(point1, point2) ;
KNearestNeighborhood<Solution<?>> neighborhood = new KNearestNeighborhood<>(1) ;
List<Solution<?>> neighbors = neighborhood.getNeighbors(solutionList, 0) ;
assertEquals(1, neighbors.size());
assertSame(point2, neighbors.get(0));
}
示例13: shouldIdenticalPointsHaveADistanceOfOne
import org.uma.jmetal.solution.Solution; //导入依赖的package包/类
@Test
public void shouldIdenticalPointsHaveADistanceOfOne() {
Solution<?> idealPoint = mock(Solution.class) ;
when(idealPoint.getObjective(0)).thenReturn(0.0) ;
when(idealPoint.getObjective(1)).thenReturn(0.0) ;
when(idealPoint.getNumberOfObjectives()).thenReturn(3) ;
Solution<?> point1 = mock(Solution.class) ;
when(point1.getObjective(0)).thenReturn(1.0) ;
when(point1.getObjective(1)).thenReturn(1.0) ;
when(point1.getNumberOfObjectives()).thenReturn(3) ;
Solution<?> point2 = mock(Solution.class) ;
when(point2.getObjective(0)).thenReturn(1.0) ;
when(point2.getObjective(1)).thenReturn(1.0) ;
when(point2.getNumberOfObjectives()).thenReturn(3) ;
CosineDistanceBetweenSolutionsInObjectiveSpace<Solution<?>> distance =
new CosineDistanceBetweenSolutionsInObjectiveSpace<Solution<?>>(idealPoint) ;
double receivedValue = distance.getDistance(point1, point2) ;
assertEquals(1.0, receivedValue, EPSILON) ;
}
示例14: shouldCompareRaiseAnExceptionIfSolution2HasLessObjectivesThanTheOneRequested
import org.uma.jmetal.solution.Solution; //导入依赖的package包/类
@Test public void shouldCompareRaiseAnExceptionIfSolution2HasLessObjectivesThanTheOneRequested() {
exception.expect(JMetalException.class);
exception.expectMessage(containsString("The solution2 has 5 objectives and the objective "
+ "to sort is 5"));
comparator = new ObjectiveComparator<Solution<?>>(5, ObjectiveComparator.Ordering.DESCENDING) ;
DoubleSolution solution1 = mock(DoubleSolution.class) ;
DoubleSolution solution2 = mock(DoubleSolution.class) ;
when(solution1.getNumberOfObjectives()).thenReturn(7) ;
when(solution2.getNumberOfObjectives()).thenReturn(5) ;
comparator.compare(solution1, solution2) ;
verify(solution1).getNumberOfObjectives();
verify(solution2).getNumberOfObjectives();
}
示例15: shouldExecuteReturnTheRightValueIfTheFrontsContainOnePointWhichIsNotTheSame
import org.uma.jmetal.solution.Solution; //导入依赖的package包/类
/**
* Given a frontA with point [2,3] and a frontB with point [1,2], the value of the
* setCoverage(frontA, frontB) == 0 and setCoverage(frontB, frontA) == 1
*/
@Test
public void shouldExecuteReturnTheRightValueIfTheFrontsContainOnePointWhichIsNotTheSame() {
int numberOfPoints = 1 ;
int numberOfDimensions = 2 ;
Front frontA = new ArrayFront(numberOfPoints, numberOfDimensions);
Front frontB = new ArrayFront(numberOfPoints, numberOfDimensions);
Point point1 = new ArrayPoint(numberOfDimensions) ;
point1.setDimensionValue(0, 2.0);
point1.setDimensionValue(1, 3.0);
Point point2 = new ArrayPoint(numberOfDimensions) ;
point2.setDimensionValue(0, 1.0);
point2.setDimensionValue(1, 2.0);
frontA.setPoint(0, point1);
frontB.setPoint(0, point2);
Pair<Double, Double> result = setCoverage.evaluate(new ImmutablePair<List<? extends Solution<?>>, List<? extends Solution<?>>>(
FrontUtils.convertFrontToSolutionList(frontA),
FrontUtils.convertFrontToSolutionList(frontB))) ;
assertEquals(0.0, result.getLeft(), EPSILON);
assertEquals(1.0, result.getRight(), EPSILON);
}