Skip to content

Commit

Permalink
improved experiment API naming
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasWeise committed Feb 8, 2020
1 parent fe94faa commit 9408643
Show file tree
Hide file tree
Showing 6 changed files with 324 additions and 134 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

[<img alt="Travis CI Build Status" src="https://img.shields.io/travis/thomasWeise/aitoa-code/master.svg" height="20"/>](https://travis-ci.org/thomasWeise/aitoa-code/)
[<img alt="AppVeyor Build Status" src="https://img.shields.io/appveyor/ci/thomasWeise/aitoa-code.svg" height="20"/>](https://ci.appveyor.com/project/thomasWeise/aitoa-code)
[<img alt="drone.io Build Status" src="https://cloud.drone.io/api/badges/thomasWeise/aitoa-code/status.svg" height="20">](https://cloud.drone.io/thomasWeise/aitoa-code)
[![Release](https://jitpack.io/v/thomasWeise/aitoa-code.svg)](https://jitpack.io/#thomasWeise/aitoa-code)


## 1. Introduction

In this repository, we provide example source codes for the book "[An Introduction to Optimization Algorithms](http://github.com/thomasWeise/aitoa)".
Expand Down Expand Up @@ -44,15 +44,15 @@ First, you need to add the following repository, which is a repository that can
```

Than you can add the dependency on our `aitoa-code` repository into your `dependencies` section.
Here, `0.8.28` is the current version of `aitoa-code`.
Here, `0.8.29` is the current version of `aitoa-code`.
Notice that you may have more dependencies in your `dependencies` section, say on `junit`, but here I just put the one for `aitoa-code` as example.

```xml
<dependencies>
<dependency>
<groupId>com.github.thomasWeise</groupId>
<artifactId>aitoa-code</artifactId>
<version>0.8.28</version>
<version>0.8.29</version>
</dependency>
</dependencies>
```
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>aitoa</groupId>
<artifactId>aitoa-code</artifactId>
<version>0.8.28</version>
<version>0.8.29</version>
<packaging>jar</packaging>
<name>aitoa-code</name>
<description>Example Source Codes from the Book "Introduction to Optimization Algorithms"</description>
Expand Down
153 changes: 58 additions & 95 deletions src/main/java/aitoa/examples/jssp/EJSSPExperimentStage.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import aitoa.algorithms.TemperatureSchedule;
import aitoa.structure.BlackBoxProcessBuilder;
import aitoa.structure.IMetaheuristic;
import aitoa.utils.Experiment;
import aitoa.utils.Experiment.IExperimentStage;

/** the stages of the JSSP experiment */
Expand Down Expand Up @@ -68,7 +69,7 @@ public enum EJSSPExperimentStage implements
IMetaheuristic<int[], JSSPCandidateSolution>>>
getAlgorithms(//
final JSSPMakespanObjectiveFunction problem) {
return EJSSPExperimentStage._hillClimbers("_1swap"); //$NON-NLS-1$
return EJSSPExperimentStage._hillClimbers();
}

/**
Expand Down Expand Up @@ -106,7 +107,7 @@ public void configureBuilder(final BlackBoxProcessBuilder<
IMetaheuristic<int[], JSSPCandidateSolution>>>
getAlgorithms(//
final JSSPMakespanObjectiveFunction problem) {
return EJSSPExperimentStage._hillClimbers("_nswap"); //$NON-NLS-1$
return EJSSPExperimentStage._hillClimbers();
}

/**
Expand Down Expand Up @@ -143,7 +144,7 @@ public void configureBuilder(final BlackBoxProcessBuilder<
IMetaheuristic<int[], JSSPCandidateSolution>>>
getAlgorithms(//
final JSSPMakespanObjectiveFunction problem) {
return EJSSPExperimentStage._eas("_1swap_seqx"); //$NON-NLS-1$
return EJSSPExperimentStage._eas();
}

/**
Expand Down Expand Up @@ -199,7 +200,7 @@ public void configureBuilderForProblem(
IMetaheuristic<int[], JSSPCandidateSolution>>>
getAlgorithms(//
final JSSPMakespanObjectiveFunction problem) {
return EJSSPExperimentStage._eas("_nswap_seqx"); //$NON-NLS-1$
return EJSSPExperimentStage._eas();
}

/**
Expand Down Expand Up @@ -256,7 +257,7 @@ public void configureBuilderForProblem(
IMetaheuristic<int[], JSSPCandidateSolution>>>
getAlgorithms(//
final JSSPMakespanObjectiveFunction problem) {
return EJSSPExperimentStage._sa("_1swap"); //$NON-NLS-1$
return EJSSPExperimentStage._sa();
}

/**
Expand Down Expand Up @@ -294,7 +295,7 @@ public void configureBuilder(final BlackBoxProcessBuilder<
IMetaheuristic<int[], JSSPCandidateSolution>>>
getAlgorithms(//
final JSSPMakespanObjectiveFunction problem) {
return EJSSPExperimentStage._hc2("_1swap"); //$NON-NLS-1$
return EJSSPExperimentStage._hc2();
}

/**
Expand Down Expand Up @@ -332,7 +333,7 @@ public void configureBuilder(final BlackBoxProcessBuilder<
IMetaheuristic<int[], JSSPCandidateSolution>>>
getAlgorithms(//
final JSSPMakespanObjectiveFunction problem) {
return EJSSPExperimentStage._hc2("_1swapU"); //$NON-NLS-1$
return EJSSPExperimentStage._hc2();
}

/**
Expand Down Expand Up @@ -374,7 +375,7 @@ public void configureBuilderForProblem(
IMetaheuristic<int[], JSSPCandidateSolution>>>
getAlgorithms(//
final JSSPMakespanObjectiveFunction problem) {
return EJSSPExperimentStage._hc2("_12swap"); //$NON-NLS-1$
return EJSSPExperimentStage._hc2();
}

/**
Expand Down Expand Up @@ -465,77 +466,36 @@ public void configureBuilderForProblem(
/**
* create the stream of hill climbers
*
* @param nameSuffix
* the name suffix
* @return the stream of hill climbers
*/
static final
Stream<
Supplier<IMetaheuristic<int[], JSSPCandidateSolution>>>
_hillClimbers(final String nameSuffix) {
return Stream.of(
() -> new HillClimber<int[], JSSPCandidateSolution>() {
@Override
public String toString() {
final String r = super.toString();
return r + nameSuffix;
}
}, //
//
() -> new HillClimberWithRestarts<int[],
JSSPCandidateSolution>(256, "256", 0d) { //$NON-NLS-1$
@Override
public String toString() {
final String r = super.toString();
return r + nameSuffix;
}
},
//
() -> new HillClimberWithRestarts<int[],
JSSPCandidateSolution>(256, "256", 0.05d) { //$NON-NLS-1$
@Override
public String toString() {
final String r = super.toString();
return r + nameSuffix;
}
});
_hillClimbers() {
return Stream.of(() -> new HillClimber<>(), //
() -> new HillClimberWithRestarts<>(256, "256", 0d), //$NON-NLS-1$
() -> new HillClimberWithRestarts<>(256, "256", 0.05d)); //$NON-NLS-1$
//
}

/**
* create the stream of EAs
*
* @param nameSuffix
* the name suffix
* @return the stream of EAs
*/
static final
Stream<
Supplier<IMetaheuristic<int[], JSSPCandidateSolution>>>
_eas(final String nameSuffix) {
_eas() {

final ArrayList<Supplier<
IMetaheuristic<int[], JSSPCandidateSolution>>> list =
new ArrayList<>();

for (final int ps : new int[] { 2048, 4096 }) {
for (final double cr : new double[] { 0d, 0.05d, 0.3d }) {
list.add(() -> new EA<int[], JSSPCandidateSolution>(cr,
ps, ps) {
@Override
public String toString() {
final String r = super.toString();
return r + nameSuffix;
}
});
list.add(() -> new EAWithPruning<int[],
JSSPCandidateSolution>(cr, ps, ps) {
@Override
public String toString() {
final String r = super.toString();
return r + nameSuffix;
}
});
list.add(() -> new EA<>(cr, ps, ps));
list.add(() -> new EAWithPruning<>(cr, ps, ps));
}
}

Expand All @@ -545,42 +505,26 @@ public String toString() {
/**
* create the stream of SAs
*
* @param nameSuffix
* the name suffix
* @return the stream of SAs
*/
static final
Stream<
Supplier<IMetaheuristic<int[], JSSPCandidateSolution>>>
_sa(final String nameSuffix) {
_sa() {

final ArrayList<Supplier<
IMetaheuristic<int[], JSSPCandidateSolution>>> list =
new ArrayList<>();

for (final double Ts : new double[] { 20d, 0.5d * 20d,
0.25d * 20d }) {
list.add(() -> new SimulatedAnnealing<int[],
JSSPCandidateSolution>(
new TemperatureSchedule.Logarithmic(Ts, 1)) {
@Override
public String toString() {
final String r = super.toString();
return r + nameSuffix;
}
});
list.add(() -> new SimulatedAnnealing<>(
new TemperatureSchedule.Logarithmic(Ts, 1)));
} // end start temperature
for (final double ep : new double[] { 2e-7d, 4e-7d,
8e-7d }) {
list.add(() -> new SimulatedAnnealing<int[],
JSSPCandidateSolution>(
new TemperatureSchedule.Exponential(20d, ep)) {
@Override
public String toString() {
final String r = super.toString();
return r + nameSuffix;
}
});
list.add(() -> new SimulatedAnnealing<>(
new TemperatureSchedule.Exponential(20d, ep)));
} // end epsilon

return list.stream();
Expand All @@ -589,29 +533,48 @@ public String toString() {
/**
* create the hill climbers that enumerate neighborhoods
*
* @param nameSuffix
* the name suffix
* @return the hill climbers that enumerate neighborhoods
*/
static final
Stream<
Supplier<IMetaheuristic<int[], JSSPCandidateSolution>>>
_hc2(final String nameSuffix) {
_hc2() {
return Stream.of(//
() -> new HillClimber2<int[], JSSPCandidateSolution>() {
@Override
public String toString() {
final String r = super.toString();
return r + nameSuffix;
}
}, //
() -> new HillClimber2WithRestarts<int[],
JSSPCandidateSolution>() {
@Override
public String toString() {
final String r = super.toString();
return r + nameSuffix;
}
});
() -> new HillClimber2<>(), //
() -> new HillClimber2WithRestarts<>());
}

/**
* the name function
*
* @param algorithm
* the algorithm
* @param builder
* the builder
* @return the name
*/
static final String nameFunction(
final IMetaheuristic<int[],
JSSPCandidateSolution> algorithm,
final BlackBoxProcessBuilder<int[],
JSSPCandidateSolution> builder) {

String name =
Experiment.defaultSetupName(algorithm, builder);

if ((algorithm instanceof SingleRandomSample)
|| (algorithm instanceof RandomSampling)) {
return name;
}

name = Experiment.nameFromObjectsMerge(name, Objects
.requireNonNull(builder.getUnarySearchOperator()));
if ((algorithm instanceof EA)
|| (algorithm instanceof EAWithPruning)) {
name = Experiment.nameFromObjectsMerge(name, Objects
.requireNonNull(builder.getBinarySearchOperator()));
}

return name;
}
}
2 changes: 1 addition & 1 deletion src/main/java/aitoa/examples/jssp/JSSPExperiment.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ public static final void main(final String[] args)
Experiment.executeExperimentInParallel(
Arrays.stream(EJSSPExperimentStage.values())
.map((s) -> () -> s),
out, processors);
out, processors, EJSSPExperimentStage::nameFunction);
}
}
Loading

0 comments on commit 9408643

Please sign in to comment.