Skip to content

Commit 34679a6

Browse files
author
Admin
committed
Fonseca-Fleming example up and running
1 parent c57c927 commit 34679a6

File tree

5 files changed

+25
-23
lines changed

5 files changed

+25
-23
lines changed

JSimpleSim/.classpath

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
3-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
3+
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
44
<attributes>
55
<attribute name="module" value="true"/>
66
</attributes>

JSimpleSim/src/org/simplesim/examples/fonseca/FonsecaChart.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,29 @@
2424
import org.knowm.xchart.style.markers.SeriesMarkers;
2525

2626
/**
27+
* Class to display chart, pareto front and xy-series of algorithm
2728
*/
2829
public class FonsecaChart {
2930

31+
private final static int VISIBLE_DOTS=20;
32+
3033
private final XYChart chart;
3134
private final Deque<Double> f1=new ArrayDeque<>();
3235
private final Deque<Double> f2=new ArrayDeque<>();
3336

3437
private final SwingWrapper<XYChart> sw;
3538

3639
public FonsecaChart(String title) {
37-
chart=new XYChartBuilder().width(800).height(600).title(title).xAxisTitle("X")
38-
.yAxisTitle("Y").theme(ChartTheme.Matlab).build();
40+
chart=new XYChartBuilder().width(800).height(600).title(title).theme(ChartTheme.Matlab).build();
3941

4042
// Customize Chart
4143
chart.getStyler().setDefaultSeriesRenderStyle(XYSeriesRenderStyle.Scatter);
4244
chart.getStyler().setChartTitleVisible(false);
4345
chart.getStyler().setLegendVisible(false);
44-
chart.getStyler().setAxisTitlesVisible(false);
46+
chart.getStyler().setAxisTitlesVisible(true);
4547
chart.getStyler().setXAxisDecimalPattern("0.0");
48+
chart.setXAxisTitle("f1(x)");
49+
chart.setYAxisTitle("f2(x)");
4650

4751
XYSeries series=chart.addSeries("Algorithm",new double[1],new double[1]);
4852
series.setMarkerColor(Color.BLUE);
@@ -59,13 +63,11 @@ public void addParetoFront(double[] f1pareto, double[] f2pareto) {
5963
series.setMarker(SeriesMarkers.DIAMOND);
6064
}
6165

62-
private final int BUFFER_SIZE=20;
63-
6466
public void update(double x1, double x2) {
6567
f1.addFirst(x1);
66-
while (f1.size()>BUFFER_SIZE) f1.removeLast();
68+
while (f1.size()>VISIBLE_DOTS) f1.removeLast();
6769
f2.addFirst(x2);
68-
while (f2.size()>BUFFER_SIZE) f2.removeLast();
70+
while (f2.size()>VISIBLE_DOTS) f2.removeLast();
6971
chart.updateXYSeries("Algorithm",new ArrayList<>(f1),new ArrayList<>(f2),null);
7072
sw.repaintChart();
7173
}

JSimpleSim/src/org/simplesim/examples/fonseca/Main.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
import java.util.List;
1212
import java.util.concurrent.ThreadLocalRandom;
1313

14-
import org.simplesim.decisionmaking.AspirationAdaptation;
15-
import org.simplesim.decisionmaking.AspirationAdaptation.Action;
16-
import org.simplesim.decisionmaking.AspirationAdaptation.GoalVariable;
17-
import org.simplesim.decisionmaking.AspirationAdaptation.STRATEGY;
14+
import org.simplesim.reasoning.AspirationAdaptation;
15+
import org.simplesim.reasoning.AspirationAdaptation.Action;
16+
import org.simplesim.reasoning.AspirationAdaptation.GoalVariable;
17+
import org.simplesim.reasoning.AspirationAdaptation.STRATEGY;
1818

1919
/**
2020
* Testing the aspiration adaptation strategy by a three-parameter optimization
@@ -35,7 +35,7 @@ public class Main {
3535

3636
private static final NumberFormat nf2=NumberFormat.getInstance();
3737
private static final NumberFormat nf6=NumberFormat.getInstance();
38-
private static final int PARETO_SIZE=50; // number of dots for pareto front
38+
private static final int PARETO_DOTS=50; // number of dots for pareto front
3939
private static final double a=1/Math.sqrt(3.0d);
4040
private static final int dim=2; // number of goal variables
4141

@@ -54,10 +54,10 @@ public Main() {
5454
}
5555

5656
private void addParetoFront() {
57-
final double[] f1pareto=new double[PARETO_SIZE];
58-
final double[] f2pareto=new double[PARETO_SIZE];
59-
for (int i=0; i<PARETO_SIZE; i++) {
60-
double f1=Math.exp(-4)+(i*((1-(2*Math.exp(-4)))/PARETO_SIZE));
57+
final double[] f1pareto=new double[PARETO_DOTS];
58+
final double[] f2pareto=new double[PARETO_DOTS];
59+
for (int i=0; i<PARETO_DOTS; i++) {
60+
double f1=Math.exp(-4)+(i*((1-(2*Math.exp(-4)))/PARETO_DOTS));
6161
f1pareto[i]=f1;
6262
f2pareto[i]=Math.exp(-Math.pow(2-Math.sqrt(-Math.log(f1)),2));
6363
}
@@ -136,6 +136,10 @@ private void run() {
136136
}
137137
}
138138

139+
// value calculation of the Fonseca-Fleming function
140+
public static double f1(double x[]) { return Math.exp(-Math.pow(x[0]-a,2)-Math.pow(x[1]-a,2)-Math.pow(x[2]-a,2)); }
141+
public static double f2(double x[]) { return Math.exp(-Math.pow(x[0]+a,2)-Math.pow(x[1]+a,2)-Math.pow(x[2]+a,2)); }
142+
139143
public static void main(String[] args) {
140144
nf2.setMaximumFractionDigits(2);
141145
nf2.setMinimumFractionDigits(2);
@@ -145,8 +149,4 @@ public static void main(String[] args) {
145149
test.run();
146150
}
147151

148-
public double f1(double x[]) { return Math.exp(-Math.pow(x[0]-a,2)-Math.pow(x[1]-a,2)-Math.pow(x[2]-a,2)); }
149-
150-
public double f2(double x[]) { return Math.exp(-Math.pow(x[0]+a,2)-Math.pow(x[1]+a,2)-Math.pow(x[2]+a,2)); }
151-
152152
}

JSimpleSim/src/org/simplesim/decisionmaking/AspirationAdaptation.java renamed to JSimpleSim/src/org/simplesim/reasoning/AspirationAdaptation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* Contributors: - Rene Kuhlemann - development and initial implementation
66
*/
7-
package org.simplesim.decisionmaking;
7+
package org.simplesim.reasoning;
88

99
import java.util.ArrayDeque;
1010
import java.util.ArrayList;

JSimpleSim/src/org/simplesim/decisionmaking/package-info.java renamed to JSimpleSim/src/org/simplesim/reasoning/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
* Methods for decision-making and reasoning
33
*
44
*/
5-
package org.simplesim.decisionmaking;
5+
package org.simplesim.reasoning;

0 commit comments

Comments
 (0)