diff options
author | Todor Balabanov <todor.balabanov@gmail.com> | 2021-07-07 16:01:19 +0300 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2021-07-08 03:49:56 +0200 |
commit | 822f128e734f37ee4de9bf5b62640cbec140701e (patch) | |
tree | 2f6ca988daa20c6d766fd710b78b24629583d818 /nlpsolver | |
parent | 7a58221f800e215934cbcb2d3907c35b44981611 (diff) |
Polymorphism is a better approach when there are chains of inheritance.
Change-Id: I2580dafcf8792bf4b11db78988db8c2976e4545c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118569
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'nlpsolver')
4 files changed, 8 insertions, 12 deletions
diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/DEPSAgent.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/DEPSAgent.java index 58250089b02f..88aa56eff837 100644 --- a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/DEPSAgent.java +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/DEPSAgent.java @@ -66,7 +66,7 @@ public class DEPSAgent implements ILibEngine { // the own memory: store the personal best point private SearchPoint pbest_t; - // Generate-and-test Behaviors + // Generate-and-test behaviors. private DEGTBehavior deGTBehavior; private PSGTBehavior psGTBehavior; public double switchP = 0.5; @@ -100,16 +100,7 @@ public class DEPSAgent implements ILibEngine { } public void setGTBehavior(AbsGTBehavior gtBehavior) { - if (gtBehavior instanceof DEGTBehavior) { - deGTBehavior = ((DEGTBehavior) gtBehavior); - deGTBehavior.setPbest(pbest_t); - return; - } - if (gtBehavior instanceof PSGTBehavior) { - psGTBehavior = ((PSGTBehavior) gtBehavior); - psGTBehavior.setMemPoints(pbest_t, pcurrent_t, pold_t); - return; - } + gtBehavior.setMemPoints(pbest_t, pcurrent_t, pold_t); } public void generatePoint() { 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 b811572ada82..c96174227b93 100644 --- a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/AbsGTBehavior.java +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/AbsGTBehavior.java @@ -21,6 +21,7 @@ import net.adaptivebox.goodness.IGoodnessCompareEngine; import net.adaptivebox.knowledge.Library; import net.adaptivebox.knowledge.SearchPoint; import net.adaptivebox.problem.ProblemEncoder; +import net.adaptivebox.space.BasicPoint; abstract public class AbsGTBehavior { // The referred social library @@ -30,6 +31,8 @@ abstract public class AbsGTBehavior { socialLib = lib; } + abstract public void setMemPoints(SearchPoint pbest, BasicPoint pcurrent, BasicPoint pold); + abstract public void generateBehavior(SearchPoint trailPoint, ProblemEncoder problemEncoder); abstract public void testBehavior(SearchPoint trailPoint, IGoodnessCompareEngine qualityComparator); 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 df7ff571065d..ada457f3233c 100644 --- a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/DEGTBehavior.java +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/DEGTBehavior.java @@ -52,7 +52,8 @@ public class DEGTBehavior extends AbsGTBehavior implements ILibEngine { // the own memory: store the point that generated in last learning cycle private SearchPoint pbest_t; - public void setPbest(SearchPoint pbest) { + @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 3c7523209138..eb35a1ad4e9a 100644 --- a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/PSGTBehavior.java +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/PSGTBehavior.java @@ -85,6 +85,7 @@ public class PSGTBehavior extends AbsGTBehavior { // 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; pbest_t = pbest; |