Kaydet (Commit) 5ee45381 authored tarafından Todor Balabanov's avatar Todor Balabanov Kaydeden (comit) Samuel Mehrbrodt

Some additional manual formatting.

Change-Id: Ie5590535d013aa2f747dd034fa2fcd2ae5c3956b
Reviewed-on: https://gerrit.libreoffice.org/72226
Tested-by: Jenkins
Reviewed-by: 's avatarSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
üst acd4625f
...@@ -46,6 +46,7 @@ public class DEPSAgent implements ILibEngine { ...@@ -46,6 +46,7 @@ public class DEPSAgent implements ILibEngine {
// Describes the problem to be solved // Describes the problem to be solved
private ProblemEncoder problemEncoder; private ProblemEncoder problemEncoder;
// Forms the goodness landscape // Forms the goodness landscape
private IGoodnessCompareEngine qualityComparator; private IGoodnessCompareEngine qualityComparator;
...@@ -57,8 +58,10 @@ public class DEPSAgent implements ILibEngine { ...@@ -57,8 +58,10 @@ public class DEPSAgent implements ILibEngine {
// the own memory: store the point that generated in old learning cycle // the own memory: store the point that generated in old learning cycle
private BasicPoint pold_t; private BasicPoint pold_t;
// the own memory: store the point that generated in last learning cycle // the own memory: store the point that generated in last learning cycle
private BasicPoint pcurrent_t; private BasicPoint pcurrent_t;
// the own memory: store the personal best point // the own memory: store the personal best point
private SearchPoint pbest_t; private SearchPoint pbest_t;
...@@ -109,11 +112,12 @@ public class DEPSAgent implements ILibEngine { ...@@ -109,11 +112,12 @@ public class DEPSAgent implements ILibEngine {
} }
public void generatePoint() { public void generatePoint() {
// generates a new point in the search space (S) based on // generates a new point in the search space (S) based on
// its memory and the library // its memory and the library
selectGTBehavior = this.getGTBehavior(); selectGTBehavior = this.getGTBehavior();
selectGTBehavior.generateBehavior(trailPoint, problemEncoder); selectGTBehavior.generateBehavior(trailPoint, problemEncoder);
// evaluate into goodness information
// evaluate into goodness information
problemEncoder.evaluate(trailPoint); problemEncoder.evaluate(trailPoint);
} }
......
...@@ -37,9 +37,14 @@ import net.adaptivebox.problem.ProblemEncoder; ...@@ -37,9 +37,14 @@ import net.adaptivebox.problem.ProblemEncoder;
import net.adaptivebox.space.BasicPoint; import net.adaptivebox.space.BasicPoint;
public class DEGTBehavior extends AbsGTBehavior implements ILibEngine { public class DEGTBehavior extends AbsGTBehavior implements ILibEngine {
private static final int DVNum = 2; // Number of differential vectors, normally be 1 or 2 //Number of differential vectors, normally be 1 or 2
public double FACTOR = 0.5; // scale constant: (0, 1.2], normally be 0.5 private static final int DVNum = 2;
public double CR = 0.9; // crossover constant: [0, 1], normally be 0.1 or 0.9
//scale constant: (0, 1.2], normally be 0.5
public double FACTOR = 0.5;
//crossover constant: [0, 1], normally be 0.1 or 0.9
public double CR = 0.9;
// the own memory: store the point that generated in last learning cycle // the own memory: store the point that generated in last learning cycle
private SearchPoint pbest_t; private SearchPoint pbest_t;
......
...@@ -64,20 +64,23 @@ import net.adaptivebox.space.DesignSpace; ...@@ -64,20 +64,23 @@ import net.adaptivebox.space.DesignSpace;
public class PSGTBehavior extends AbsGTBehavior { public class PSGTBehavior extends AbsGTBehavior {
// Two normally choices for (c1, c2, weight), i.e., (2, 2, 0.4), or (1.494, // Two normally choices for (c1, c2, weight), i.e., (2, 2, 0.4), or (1.494,
// 1.494, 0.729) // 1.494, 0.729) The first is used in dissipative PSO (cf. [4]) as CL>0, and
// The first is used in dissipative PSO (cf. [4]) as CL>0, and the second is // the second is achieved by using constriction factors (cf. [3])
// achieved by using
// constriction factors (cf. [3])
public double c1 = 2; public double c1 = 2;
public double c2 = 2; public double c2 = 2;
public double weight = 0.4; // inertia weight
public double CL = 0; // See ref[4], normally be 0.001~0.005 //inertia weight
public double weight = 0.4;
//See ref[4], normally be 0.001~0.005
public double CL = 0;
// the own memory: store the point that generated in old learning cycle // the own memory: store the point that generated in old learning cycle
private BasicPoint pold_t; private BasicPoint pold_t;
// the own memory: store the point that generated in last learning cycle // the own memory: store the point that generated in last learning cycle
private BasicPoint pcurrent_t; private BasicPoint pcurrent_t;
// the own memory: store the personal best point // the own memory: store the personal best point
private SearchPoint pbest_t; private SearchPoint pbest_t;
...@@ -100,7 +103,8 @@ public class PSGTBehavior extends AbsGTBehavior { ...@@ -100,7 +103,8 @@ public class PSGTBehavior extends AbsGTBehavior {
deltaxb = weight * (pcurrent_t.getLocation()[b] - pold_t.getLocation()[b]) deltaxb = weight * (pcurrent_t.getLocation()[b] - pold_t.getLocation()[b])
+ c1 * Math.random() * (pbest_t.getLocation()[b] - pcurrent_t.getLocation()[b]) + c1 * Math.random() * (pbest_t.getLocation()[b] - pcurrent_t.getLocation()[b])
+ c2 * Math.random() * (gbest_t.getLocation()[b] - pcurrent_t.getLocation()[b]); + c2 * Math.random() * (gbest_t.getLocation()[b] - pcurrent_t.getLocation()[b]);
// limitation for delta_x
// limitation for delta_x
deltaxbm = 0.5 * designSpace.getMagnitudeIn(b); deltaxbm = 0.5 * designSpace.getMagnitudeIn(b);
if (deltaxb < -deltaxbm) { if (deltaxb < -deltaxbm) {
deltaxb = -deltaxbm; deltaxb = -deltaxbm;
...@@ -118,5 +122,4 @@ public class PSGTBehavior extends AbsGTBehavior { ...@@ -118,5 +122,4 @@ public class PSGTBehavior extends AbsGTBehavior {
pold_t.importLocation(pcurrent_t); pold_t.importLocation(pcurrent_t);
pcurrent_t.importLocation(trailPoint); pcurrent_t.importLocation(trailPoint);
} }
} }
...@@ -42,13 +42,13 @@ public class EvalStruct { ...@@ -42,13 +42,13 @@ public class EvalStruct {
evalRes[0] = evalRes[1] = 0; evalRes[0] = evalRes[1] = 0;
for (int i = 0; i < evalElems.length; i++) { for (int i = 0; i < evalElems.length; i++) {
if (evalElems[i].isOptType()) { if (evalElems[i].isOptType()) {
// The objectives (OPTIM type) // The objectives (OPTIM type)
// The multi-objective will be translated into single-objective // The multi-objective will be translated into single-objective
evalRes[1] += evalElems[i].evaluateOPTIM(targetValues[i]); evalRes[1] += evalElems[i].evaluateOPTIM(targetValues[i]);
} else { } else {
// The constraints (CONS type) // The constraints (CONS type)
// If evalRes[0] equals to 0, then be a feasible point, i.e. satisfies // If evalRes[0] equals to 0, then be a feasible point, i.e. satisfies
// all the constraints // all the constraints
evalRes[0] += evalElems[i].evaluateCONS(targetValues[i]); evalRes[0] += evalElems[i].evaluateCONS(targetValues[i]);
} }
} }
......
...@@ -51,8 +51,8 @@ public class ACRComparator implements IGoodnessCompareEngine, IUpdateCycleEngine ...@@ -51,8 +51,8 @@ public class ACRComparator implements IGoodnessCompareEngine, IUpdateCycleEngine
public ACRComparator(Library lib, int T) { public ACRComparator(Library lib, int T) {
socialPool = lib; socialPool = lib;
this.T = T; this.T = T;
// set the (epsilon_t|t=0) as the maximum CONS value among the SearchPoints in
// the library // set the (epsilon_t|t=0) as the maximum CONS value among the SearchPoints in the library
epsilon_t = lib.getExtremalVcon(true); epsilon_t = lib.getExtremalVcon(true);
} }
...@@ -74,8 +74,9 @@ public class ACRComparator implements IGoodnessCompareEngine, IUpdateCycleEngine ...@@ -74,8 +74,9 @@ public class ACRComparator implements IGoodnessCompareEngine, IUpdateCycleEngine
} }
public void updateCycle(int t) { public void updateCycle(int t) {
// calculates the ratio // calculates the ratio
double rn = (double) socialPool.getVconThanNum(epsilon_t) / (double) socialPool.getPopSize(); double rn = (double) socialPool.getVconThanNum(epsilon_t) / (double) socialPool.getPopSize();
if (t > TthR * T && T != -1) { // Forcing sub-rule if (t > TthR * T && T != -1) { // Forcing sub-rule
epsilon_t *= BETAF; epsilon_t *= BETAF;
} else { // Ratio-keeping sub-rules } else { // Ratio-keeping sub-rules
......
...@@ -28,9 +28,7 @@ package net.adaptivebox.goodness; ...@@ -28,9 +28,7 @@ package net.adaptivebox.goodness;
public class BCHComparator implements IGoodnessCompareEngine { public class BCHComparator implements IGoodnessCompareEngine {
/* /* check the magnitude of two array, the frontal is more important */
* check the magnitude of two array, the frontal is more important
**/
private static int compareArray(double[] fit1, double[] fit2) { private static int compareArray(double[] fit1, double[] fit2) {
for (int i = 0; i < fit1.length; i++) { for (int i = 0; i < fit1.length; i++) {
if (fit1[i] > fit2[i]) { if (fit1[i] > fit2[i]) {
......
...@@ -29,9 +29,13 @@ public abstract interface IGoodnessCompareEngine { ...@@ -29,9 +29,13 @@ public abstract interface IGoodnessCompareEngine {
int LESS_THAN = 0; int LESS_THAN = 0;
/** /**
* check the magnitude of two IEncodeEngine LARGER_THAN: goodness1 is worse than * check the magnitude of two IEncodeEngine
* goodness2 LESS_THAN: goodness1 is better than goodness2 EQUAL_TO : goodness1 *
* is equal to goodness2 * LARGER_THAN: goodness1 is worse than goodness2
**/ *
* LESS_THAN: goodness1 is better than goodness2
*
* EQUAL_TO : goodness1 is equal to goodness2
*/
int compare(double[] goodness1, double[] goodness2); int compare(double[] goodness1, double[] goodness2);
} }
...@@ -99,5 +99,4 @@ public class Library { ...@@ -99,5 +99,4 @@ public class Library {
} }
return num; return num;
} }
} }
...@@ -25,8 +25,7 @@ import net.adaptivebox.space.BasicPoint; ...@@ -25,8 +25,7 @@ import net.adaptivebox.space.BasicPoint;
public class SearchPoint extends BasicPoint implements IEncodeEngine { public class SearchPoint extends BasicPoint implements IEncodeEngine {
// store the encode information for goodness evaluation // store the encode information for goodness evaluation
// encodeInfo[0]: the sum of constraints (if it equals to 0, then be a feasible // encodeInfo[0]: the sum of constraints (if it equals to 0, then be a feasible point)
// point)
// encodeInfo[1]: the value of objective function // encodeInfo[1]: the value of objective function
private final double[] encodeInfo = new double[2]; private final double[] encodeInfo = new double[2];
private double objectiveValue; private double objectiveValue;
...@@ -68,5 +67,4 @@ public class SearchPoint extends BasicPoint implements IEncodeEngine { ...@@ -68,5 +67,4 @@ public class SearchPoint extends BasicPoint implements IEncodeEngine {
public boolean isFeasible() { public boolean isFeasible() {
return encodeInfo[0] == 0; // no constraint violations return encodeInfo[0] == 0; // no constraint violations
} }
}
}
\ No newline at end of file
...@@ -85,11 +85,13 @@ public abstract class ProblemEncoder { ...@@ -85,11 +85,13 @@ public abstract class ProblemEncoder {
// evaluate the point into encoded information // evaluate the point into encoded information
public void evaluate(SearchPoint point) { public void evaluate(SearchPoint point) {
// copy to temp point // copy to temp point
System.arraycopy(point.getLocation(), 0, this.tempLocation, 0, tempLocation.length); System.arraycopy(point.getLocation(), 0, this.tempLocation, 0, tempLocation.length);
// mapping the temp point to original search space S
// mapping the temp point to original search space S
designSpace.getMappingPoint(tempLocation); designSpace.getMappingPoint(tempLocation);
// calculate based on the temp point
// calculate based on the temp point
calcTargets(tempResponseSet, tempLocation); calcTargets(tempResponseSet, tempLocation);
evalStruct.evaluate(point.getEncodeInfo(), tempResponseSet); evalStruct.evaluate(point.getEncodeInfo(), tempResponseSet);
point.setObjectiveValue(tempResponseSet[0]); point.setObjectiveValue(tempResponseSet[0]);
......
...@@ -43,22 +43,24 @@ import net.adaptivebox.knowledge.SearchPoint; ...@@ -43,22 +43,24 @@ import net.adaptivebox.knowledge.SearchPoint;
public class SCAgent { public class SCAgent {
// Describes the problem to be solved (encode the point into intermediate // Describes the problem to be solved (encode the point into intermediate information)
// information)
private ProblemEncoder problemEncoder; private ProblemEncoder problemEncoder;
// Forms the goodness landscape // Forms the goodness landscape
private IGoodnessCompareEngine specComparator; private IGoodnessCompareEngine specComparator;
// the coefficients of SCAgent // the coefficients of SCAgent
private static final int TaoB = 2; private static final int TaoB = 2;
// The early version set TaoW as the size of external library (NL), but 4 is
// often enough // The early version set TaoW as the size of external library (NL), but 4 is often enough
private static final int TaoW = 4; private static final int TaoW = 4;
// The referred external library // The referred external library
private Library externalLib; private Library externalLib;
// store the point that generated in current learning cycle // store the point that generated in current learning cycle
private SearchPoint trailPoint; private SearchPoint trailPoint;
// the own memory: store the point that generated in last learning cycle // the own memory: store the point that generated in last learning cycle
private SearchPoint pcurrent_t; private SearchPoint pcurrent_t;
...@@ -77,9 +79,10 @@ public class SCAgent { ...@@ -77,9 +79,10 @@ public class SCAgent {
} }
public SearchPoint generatePoint() { public SearchPoint generatePoint() {
// generate a new point // generate a new point
generatePoint(trailPoint); generatePoint(trailPoint);
// evaluate the generated point
// evaluate the generated point
problemEncoder.evaluate(trailPoint); problemEncoder.evaluate(trailPoint);
return trailPoint; return trailPoint;
} }
...@@ -87,13 +90,14 @@ public class SCAgent { ...@@ -87,13 +90,14 @@ public class SCAgent {
private void generatePoint(ILocationEngine tempPoint) { private void generatePoint(ILocationEngine tempPoint) {
SearchPoint Xmodel, Xrefer, libBPoint; SearchPoint Xmodel, Xrefer, libBPoint;
// choose Selects a better point (libBPoint) from externalLib (L) based // choose Selects a better point (libBPoint) from externalLib (L) based
// on tournament selection // on tournament selection
int xb = externalLib.tournamentSelection(specComparator, TaoB, true); int xb = externalLib.tournamentSelection(specComparator, TaoB, true);
libBPoint = externalLib.getSelectedPoint(xb); libBPoint = externalLib.getSelectedPoint(xb);
// Compares pcurrent_t with libBPoint
// The better one becomes model point (Xmodel) // Compares pcurrent_t with libBPoint
// The worse one becomes refer point (Xrefer) // The better one becomes model point (Xmodel)
// The worse one becomes refer point (Xrefer)
if (specComparator.compare(pcurrent_t.getEncodeInfo(), if (specComparator.compare(pcurrent_t.getEncodeInfo(),
libBPoint.getEncodeInfo()) == IGoodnessCompareEngine.LARGER_THAN) { libBPoint.getEncodeInfo()) == IGoodnessCompareEngine.LARGER_THAN) {
Xmodel = libBPoint; Xmodel = libBPoint;
...@@ -102,19 +106,22 @@ public class SCAgent { ...@@ -102,19 +106,22 @@ public class SCAgent {
Xmodel = pcurrent_t; Xmodel = pcurrent_t;
Xrefer = libBPoint; Xrefer = libBPoint;
} }
// observational learning: generates a new point near the model point, which
// the variation range is decided by the difference of Xmodel and Xrefer // observational learning: generates a new point near the model point, which
// the variation range is decided by the difference of Xmodel and Xrefer
inferPoint(tempPoint, Xmodel, Xrefer, problemEncoder.getDesignSpace()); inferPoint(tempPoint, Xmodel, Xrefer, problemEncoder.getDesignSpace());
} }
// 1. Update the current point into the external library // 1. Update the current point into the external library
// 2. Replace the current point by the generated point // 2. Replace the current point by the generated point
public void updateInfo() { public void updateInfo() {
// Selects a bad point kw from TaoW points in Library // Selects a bad point kw from TaoW points in Library
int xw = externalLib.tournamentSelection(specComparator, TaoW, false); int xw = externalLib.tournamentSelection(specComparator, TaoW, false);
// Replaces kw with pcurrent_t
// Replaces kw with pcurrent_t
externalLib.getSelectedPoint(xw).importPoint(pcurrent_t); externalLib.getSelectedPoint(xw).importPoint(pcurrent_t);
// Replaces pcurrent_t (x(t)) with trailPoint (x(t+1))
// Replaces pcurrent_t (x(t)) with trailPoint (x(t+1))
pcurrent_t.importPoint(trailPoint); pcurrent_t.importPoint(trailPoint);
} }
......
...@@ -42,5 +42,4 @@ public class DesignDim { ...@@ -42,5 +42,4 @@ public class DesignDim {
return paramBound.maxValue - Math.rint((paramBound.maxValue - value) / grain) * grain; return paramBound.maxValue - Math.rint((paramBound.maxValue - value) / grain) * grain;
} }
} }
} }
...@@ -70,5 +70,4 @@ public class DesignSpace { ...@@ -70,5 +70,4 @@ public class DesignSpace {
} }
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment