summaryrefslogtreecommitdiff
path: root/nlpsolver
diff options
context:
space:
mode:
authorTodor Balabanov <todor.balabanov@gmail.com>2021-07-27 20:13:32 +0300
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-08-02 08:41:14 +0200
commit559b342a62901754222723ee522f5ae80e4d40f5 (patch)
treec0eb677a603199c7b5898e354f8fdd92d7371bb6 /nlpsolver
parente98f04cedff85fd6a355a67cabd507782e2f693b (diff)
The null pointer bug should be fixed now.
Change-Id: I8278bfed8170907a958396839d0997fc127f4b2e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119744 Tested-by: Julien Nabet <serval2412@yahoo.fr> Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'nlpsolver')
-rw-r--r--nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/DEPSAgent.java33
-rw-r--r--nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/AbsGTBehavior.java7
-rw-r--r--nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/DEGTBehavior.java3
-rw-r--r--nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/PSGTBehavior.java3
-rw-r--r--nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/DEPSSolverImpl.java5
5 files changed, 24 insertions, 27 deletions
diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/DEPSAgent.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/DEPSAgent.java
index 75e66ff251b6..ae718e63519b 100644
--- a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/DEPSAgent.java
+++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/DEPSAgent.java
@@ -72,31 +72,22 @@ public class DEPSAgent {
private double switchP = 0.5;
- public DEPSAgent(ProblemEncoder encoder, DEGTBehavior deGTBehavior, PSGTBehavior psGTBehavior, double switchP, IGoodnessCompareEngine comparer, Library lib) {
- setProblemEncoder(encoder);
-
+ public DEPSAgent(ProblemEncoder encoder, DEGTBehavior deGTBehavior, PSGTBehavior psGTBehavior, double switchP, IGoodnessCompareEngine comparer) {
this.switchP = switchP;
- deGTBehavior.setLibrary(lib);
- psGTBehavior.setLibrary(lib);
- setGTBehavior(deGTBehavior);
- setGTBehavior(psGTBehavior);
- this.deGTBehavior = deGTBehavior;
- this.psGTBehavior = psGTBehavior;
+ problemEncoder = encoder;
qualityComparator = comparer;
- }
- public void setLibrary(Library lib) {
- deGTBehavior.setLibrary(lib);
- psGTBehavior.setLibrary(lib);
- }
+ trailPoint = problemEncoder.getFreshSearchPoint();
+ pold_t = problemEncoder.getFreshSearchPoint();
+ pcurrent_t = problemEncoder.getFreshSearchPoint();
+
+ this.deGTBehavior = deGTBehavior;
+ this.deGTBehavior.setMemPoints(pbest_t, pcurrent_t, pold_t);
- public void setProblemEncoder(ProblemEncoder encoder) {
- problemEncoder = encoder;
- trailPoint = problemEncoder.getFreshSearchPoint();
- pold_t = problemEncoder.getFreshSearchPoint();
- pcurrent_t = problemEncoder.getFreshSearchPoint();
+ this.psGTBehavior = psGTBehavior;
+ this.psGTBehavior.setMemPoints(pbest_t, pcurrent_t, pold_t);
}
public void setSpecComparator(IGoodnessCompareEngine comparer) {
@@ -105,6 +96,8 @@ public class DEPSAgent {
public void setPbest(SearchPoint pbest) {
pbest_t = pbest;
+ deGTBehavior.setPbest(pbest_t);
+ psGTBehavior.setPbest(pbest_t);
}
private AbsGTBehavior getGTBehavior() {
@@ -122,7 +115,7 @@ public class DEPSAgent {
public void generatePoint() {
// generates a new point in the search space (S) based on
// its memory and the library
- selectGTBehavior = this.getGTBehavior();
+ selectGTBehavior = getGTBehavior();
selectGTBehavior.generateBehavior(trailPoint, problemEncoder);
// evaluate into goodness information
diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/AbsGTBehavior.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/AbsGTBehavior.java
index b6aacd3ccc40..09110581659c 100644
--- a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/AbsGTBehavior.java
+++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/AbsGTBehavior.java
@@ -28,10 +28,17 @@ abstract public class AbsGTBehavior implements ILibEngine {
// The referred social library
protected Library socialLib;
+ // the own memory: store the personal best point
+ protected SearchPoint pbest_t;
+
public void setLibrary(Library lib) {
socialLib = lib;
}
+ public void setPbest(SearchPoint pbest) {
+ pbest_t = pbest;
+ }
+
abstract public void setMemPoints(SearchPoint pbest, BasicPoint pcurrent, BasicPoint pold);
abstract public void generateBehavior(SearchPoint trailPoint, ProblemEncoder problemEncoder);
diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/DEGTBehavior.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/DEGTBehavior.java
index 21bc2fb82de3..c9ca0ef82e59 100644
--- a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/DEGTBehavior.java
+++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/DEGTBehavior.java
@@ -48,9 +48,6 @@ public class DEGTBehavior extends AbsGTBehavior {
//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
- private SearchPoint pbest_t;
-
@Override
public void setMemPoints(SearchPoint pbest, BasicPoint pcurrent, BasicPoint pold) {
pbest_t = pbest;
diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/PSGTBehavior.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/PSGTBehavior.java
index eb35a1ad4e9a..68bf5a10edd9 100644
--- a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/PSGTBehavior.java
+++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/PSGTBehavior.java
@@ -82,9 +82,6 @@ public class PSGTBehavior extends AbsGTBehavior {
// the own memory: store the point that generated in last learning cycle
private BasicPoint pcurrent_t;
- // the own memory: store the personal best point
- private SearchPoint pbest_t;
-
@Override
public void setMemPoints(SearchPoint pbest, BasicPoint pcurrent, BasicPoint pold) {
pcurrent_t = pcurrent;
diff --git a/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/DEPSSolverImpl.java b/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/DEPSSolverImpl.java
index 20cf9286e91a..7a4c552d9e60 100644
--- a/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/DEPSSolverImpl.java
+++ b/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/DEPSSolverImpl.java
@@ -36,6 +36,7 @@ import net.adaptivebox.deps.behavior.PSGTBehavior;
import net.adaptivebox.global.IUpdateCycleEngine;
import net.adaptivebox.knowledge.Library;
import net.adaptivebox.knowledge.SearchPoint;
+import net.adaptivebox.space.BasicPoint;
import com.sun.star.comp.Calc.NLPSolver.dialogs.IEvolutionarySolverStatusDialog;
import com.sun.star.lang.IllegalArgumentException;
@@ -131,14 +132,16 @@ public final class DEPSSolverImpl extends BaseEvolutionarySolver
deGTBehavior.MIN_FACTOR = Math.min(m_minFactor.getValue(), m_maxFactor.getValue());
deGTBehavior.MAX_FACTOR = Math.max(m_minFactor.getValue(), m_maxFactor.getValue());
deGTBehavior.CR = m_CR.getValue();
+ deGTBehavior.setLibrary(m_library);
PSGTBehavior psGTBehavior = new PSGTBehavior();
psGTBehavior.c1 = m_c1.getValue();
psGTBehavior.c2 = m_c2.getValue();
psGTBehavior.CL = m_CL.getValue();
psGTBehavior.weight = m_weight.getValue();
+ psGTBehavior.setLibrary(m_library);
- agents[i] = new DEPSAgent(m_problemEncoder, deGTBehavior, psGTBehavior, m_agentSwitchRate.getValue(), m_specCompareEngine, m_library);
+ agents[i] = new DEPSAgent(m_problemEncoder, deGTBehavior, psGTBehavior, m_agentSwitchRate.getValue(), m_specCompareEngine);
agents[i].setPbest(m_library.getSelectedPoint(i));
}