From 58c271ad03b92991817cff5eace81fcac6430122 Mon Sep 17 00:00:00 2001 From: Jochen Keil Date: Wed, 30 Jun 2010 09:18:43 +0200 Subject: [PATCH] make the mediator object an abstract class for extension it is better to have a subclass of mediator for every algorithm with it's own parameters. This also requires the strategie classes to use the correct mediator object. --- aco/AntMain.java | 13 +++--- aco/mediator/ACOMediator.java | 50 +----------------------- aco/mediator/acs/ACSMediator.java | 23 +++++++++++ aco/mediator/as/ASMediator.java | 23 +++++++++++ aco/mediator/asrank/ASRankMediator.java | 31 +++++++++++++++ aco/mediator/eas/EASMediator.java | 31 +++++++++++++++ aco/strategy/acs/ACSStrategy.java | 3 ++ aco/strategy/as/ASChoiceInformationStrategy.java | 3 ++ aco/strategy/as/ASPheromoneStrategy.java | 3 ++ aco/strategy/asrank/ASRankPheromoneStrategy.java | 3 ++ aco/strategy/asrank/ASRankTauZeroStrategy.java | 3 ++ aco/strategy/eas/EASPheromoneStrategy.java | 3 ++ aco/strategy/eas/EASTauZeroStrategy.java | 3 ++ 13 files changed, 138 insertions(+), 54 deletions(-) create mode 100644 aco/mediator/acs/ACSMediator.java create mode 100644 aco/mediator/as/ASMediator.java create mode 100644 aco/mediator/asrank/ASRankMediator.java create mode 100644 aco/mediator/eas/EASMediator.java diff --git a/aco/AntMain.java b/aco/AntMain.java index fba2697..7c8587e 100644 --- a/aco/AntMain.java +++ b/aco/AntMain.java @@ -10,7 +10,10 @@ import aco.strategy.as.*; import aco.strategy.acs.*; import aco.strategy.eas.*; import aco.strategy.asrank.*; -import aco.mediator.*; +import aco.mediator.as.*; +import aco.mediator.acs.*; +import aco.mediator.eas.*; +import aco.mediator.asrank.*; import aco.parameter.as.*; import aco.parameter.acs.*; import aco.parameter.eas.*; @@ -28,7 +31,7 @@ public class AntMain { int numofants, int runs) { - ACOMediator acom = new ACOMediator(new ACSParameter()); + ACSMediator acom = new ACSMediator(new ACSParameter()); ACOGraph acog = new ACOGraph(acom); acom.setACOGraph(acog); @@ -91,7 +94,7 @@ public class AntMain { double roh, int numofants, int runs) { - ACOMediator acom = new ACOMediator(new ASParameter()); + ASMediator acom = new ASMediator(new ASParameter()); ACOGraph acog = new ACOGraph(acom); acom.setACOGraph(acog); @@ -156,7 +159,7 @@ public class AntMain { double e, int numofants, int runs) { - ACOMediator acom = new ACOMediator(new EASParameter()); + EASMediator acom = new EASMediator(new EASParameter()); ACOGraph acog = new ACOGraph(acom); acom.setACOGraph(acog); @@ -230,7 +233,7 @@ public class AntMain { double w, int numofants, int runs) { - ACOMediator acom = new ACOMediator(new ASRankParameter()); + ASRankMediator acom = new ASRankMediator(new ASRankParameter()); ACOGraph acog = new ACOGraph(acom); acom.setACOGraph(acog); diff --git a/aco/mediator/ACOMediator.java b/aco/mediator/ACOMediator.java index d4751db..e1ebc3e 100644 --- a/aco/mediator/ACOMediator.java +++ b/aco/mediator/ACOMediator.java @@ -9,13 +9,9 @@ import aco.graph.*; import aco.antview.*; import aco.strategy.*; import aco.parameter.*; -import aco.parameter.as.*; -import aco.parameter.acs.*; -import aco.parameter.eas.*; -import aco.parameter.asrank.*; import aco.environment.*; -public class ACOMediator +public abstract class ACOMediator implements AntViewObservable { protected ACOGraph acog; @@ -130,50 +126,6 @@ public class ACOMediator return acop.getInfinity(); } - public double getAlpha() { - if (acop instanceof ASParameter) - return ((ASParameter)acop).getAlpha(); - else if (acop instanceof EASParameter) - return ((EASParameter)acop).getAlpha(); - else if (acop instanceof ASRankParameter) - return ((ASRankParameter)acop).getAlpha(); - else - return 1.0; - } - - public void setAlpha(double Alpha) { - if (acop instanceof ASParameter) - ((ASParameter)acop).setAlpha(Alpha); - else if (acop instanceof EASParameter) - ((EASParameter)acop).setAlpha(Alpha); - else if (acop instanceof ASRankParameter) - ((ASRankParameter)acop).setAlpha(Alpha); - } - - public double getE() { - return ((EASParameter) acop).getE(); - } - - public void setE(double E) { - ((EASParameter) acop).setE(E); - } - - public double getW() { - return ((ASRankParameter) acop).getW(); - } - - public void setW(double W) { - ((ASRankParameter) acop).setW(W); - } - - public double getQZero(){ - return ((ACSParameter)acop).getQZero(); - } - - public void setQZero(double QZero){ - ((ACSParameter)acop).setQZero(QZero); - } - public double getBeta() { return acop.getBeta(); } diff --git a/aco/mediator/acs/ACSMediator.java b/aco/mediator/acs/ACSMediator.java new file mode 100644 index 0000000..0e35d62 --- /dev/null +++ b/aco/mediator/acs/ACSMediator.java @@ -0,0 +1,23 @@ +package aco.mediator.acs; + +import aco.mediator.*; +import aco.parameter.acs.*; + +public class ACSMediator + extends ACOMediator { + + protected ACSParameter acop; + + public ACSMediator(ACSParameter acop) { + super(acop); + } + + public double getQZero(){ + return acop.getQZero(); + } + + public void setQZero(double QZero){ + acop.setQZero(QZero); + } + +} diff --git a/aco/mediator/as/ASMediator.java b/aco/mediator/as/ASMediator.java new file mode 100644 index 0000000..cce021f --- /dev/null +++ b/aco/mediator/as/ASMediator.java @@ -0,0 +1,23 @@ +package aco.mediator.as; + +import aco.mediator.*; +import aco.parameter.as.*; + +public class ASMediator + extends ACOMediator { + + protected ASParameter acop; + + public ASMediator(ASParameter acop) { + super(acop); + } + + public double getAlpha() { + return acop.getAlpha(); + } + + public void setAlpha(double Alpha) { + acop.setAlpha(Alpha); + } + +} diff --git a/aco/mediator/asrank/ASRankMediator.java b/aco/mediator/asrank/ASRankMediator.java new file mode 100644 index 0000000..9f83a65 --- /dev/null +++ b/aco/mediator/asrank/ASRankMediator.java @@ -0,0 +1,31 @@ +package aco.mediator.asrank; + +import aco.mediator.*; +import aco.parameter.asrank.*; + +public class ASRankMediator + extends ACOMediator { + + protected ASRankParameter acop; + + public ASRankMediator(ASRankParameter acop) { + super(acop); + } + + public double getAlpha() { + return acop.getAlpha(); + } + + public void setAlpha(double Alpha) { + acop.setAlpha(Alpha); + } + + public double getW() { + return acop.getW(); + } + + public void setW(double W) { + acop.setW(W); + } + +} diff --git a/aco/mediator/eas/EASMediator.java b/aco/mediator/eas/EASMediator.java new file mode 100644 index 0000000..46ccaff --- /dev/null +++ b/aco/mediator/eas/EASMediator.java @@ -0,0 +1,31 @@ +package aco.mediator.eas; + +import aco.mediator.*; +import aco.parameter.eas.*; + +public class EASMediator + extends ACOMediator { + + protected EASParameter acop; + + public EASMediator(EASParameter acop) { + super(acop); + } + + public double getAlpha() { + return acop.getAlpha(); + } + + public void setAlpha(double Alpha) { + acop.setAlpha(Alpha); + } + + public double getE() { + return acop.getE(); + } + + public void setE(double E) { + acop.setE(E); + } + +} diff --git a/aco/strategy/acs/ACSStrategy.java b/aco/strategy/acs/ACSStrategy.java index 16c2351..0512df0 100644 --- a/aco/strategy/acs/ACSStrategy.java +++ b/aco/strategy/acs/ACSStrategy.java @@ -3,10 +3,13 @@ package aco.strategy.acs; import aco.ant.*; import aco.strategy.*; import aco.mediator.*; +import aco.mediator.acs.*; public class ACSStrategy extends ACOStrategy{ + protected ACSMediator acom; + public ACSStrategy(ACOMediator acom) { super(acom); } diff --git a/aco/strategy/as/ASChoiceInformationStrategy.java b/aco/strategy/as/ASChoiceInformationStrategy.java index e6d7a74..8b8337c 100644 --- a/aco/strategy/as/ASChoiceInformationStrategy.java +++ b/aco/strategy/as/ASChoiceInformationStrategy.java @@ -2,10 +2,13 @@ package aco.strategy.as; import aco.strategy.*; import aco.mediator.*; +import aco.mediator.as.*; public class ASChoiceInformationStrategy extends ChoiceInformationStrategy { + protected ASMediator acom; + public ASChoiceInformationStrategy(ACOMediator acom) { super(acom); } diff --git a/aco/strategy/as/ASPheromoneStrategy.java b/aco/strategy/as/ASPheromoneStrategy.java index 51a2423..9677f89 100644 --- a/aco/strategy/as/ASPheromoneStrategy.java +++ b/aco/strategy/as/ASPheromoneStrategy.java @@ -3,10 +3,13 @@ package aco.strategy.as; import aco.ant.*; import aco.strategy.*; import aco.mediator.*; +import aco.mediator.as.*; public class ASPheromoneStrategy extends PheromoneStrategy { + protected ASMediator acom; + public ASPheromoneStrategy(ACOMediator acom) { super(acom); } diff --git a/aco/strategy/asrank/ASRankPheromoneStrategy.java b/aco/strategy/asrank/ASRankPheromoneStrategy.java index 418f290..aa52368 100644 --- a/aco/strategy/asrank/ASRankPheromoneStrategy.java +++ b/aco/strategy/asrank/ASRankPheromoneStrategy.java @@ -6,10 +6,13 @@ import java.util.SortedMap; import aco.ant.*; import aco.strategy.*; import aco.mediator.*; +import aco.mediator.asrank.*; public class ASRankPheromoneStrategy extends PheromoneStrategy { + protected ASRankMediator acom; + public ASRankPheromoneStrategy(ACOMediator acom) { super(acom); } diff --git a/aco/strategy/asrank/ASRankTauZeroStrategy.java b/aco/strategy/asrank/ASRankTauZeroStrategy.java index 7c9a9d5..c5833b8 100644 --- a/aco/strategy/asrank/ASRankTauZeroStrategy.java +++ b/aco/strategy/asrank/ASRankTauZeroStrategy.java @@ -2,10 +2,13 @@ package aco.strategy.asrank; import aco.strategy.*; import aco.mediator.*; +import aco.mediator.asrank.*; public class ASRankTauZeroStrategy extends TauZeroStrategy { + protected ASRankMediator acom; + public ASRankTauZeroStrategy(ACOMediator acom) { super(acom); } diff --git a/aco/strategy/eas/EASPheromoneStrategy.java b/aco/strategy/eas/EASPheromoneStrategy.java index 440379c..bf3aded 100644 --- a/aco/strategy/eas/EASPheromoneStrategy.java +++ b/aco/strategy/eas/EASPheromoneStrategy.java @@ -3,10 +3,13 @@ package aco.strategy.eas; import aco.ant.*; import aco.strategy.*; import aco.mediator.*; +import aco.mediator.eas.*; public class EASPheromoneStrategy extends PheromoneStrategy { + protected EASMediator acom; + public EASPheromoneStrategy(ACOMediator acom) { super(acom); } diff --git a/aco/strategy/eas/EASTauZeroStrategy.java b/aco/strategy/eas/EASTauZeroStrategy.java index d59bdb2..e7166b3 100644 --- a/aco/strategy/eas/EASTauZeroStrategy.java +++ b/aco/strategy/eas/EASTauZeroStrategy.java @@ -2,10 +2,13 @@ package aco.strategy.eas; import aco.strategy.*; import aco.mediator.*; +import aco.mediator.eas.*; public class EASTauZeroStrategy extends TauZeroStrategy { + protected EASMediator acom; + public EASTauZeroStrategy(ACOMediator acom) { super(acom); } -- 2.11.4.GIT