Enhance simulation options in InteractiveConsole; add confidence index handling and new seed generation; update Plot behavior to dispose on close
This commit is contained in:
@@ -1,16 +1,15 @@
|
|||||||
package net.berack.upo.valpre;
|
package net.berack.upo.valpre;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
import com.esotericsoftware.kryo.KryoException;
|
import com.esotericsoftware.kryo.KryoException;
|
||||||
|
|
||||||
import net.berack.upo.valpre.rand.Distribution;
|
import net.berack.upo.valpre.rand.Distribution;
|
||||||
|
import net.berack.upo.valpre.rand.Rng;
|
||||||
import net.berack.upo.valpre.sim.Net;
|
import net.berack.upo.valpre.sim.Net;
|
||||||
import net.berack.upo.valpre.sim.ServerNode;
|
import net.berack.upo.valpre.sim.ServerNode;
|
||||||
|
|
||||||
@@ -137,16 +136,18 @@ public class InteractiveConsole {
|
|||||||
/**
|
/**
|
||||||
* Run the simulation with the net.
|
* Run the simulation with the net.
|
||||||
*/
|
*/
|
||||||
private void simpleRuns() throws InterruptedException, ExecutionException, IOException {
|
private void simpleRuns() throws Exception {
|
||||||
var choice = choose("Choose what to do:", "100 Run", "1K Runs", "1K Runs + Plot");
|
var choice = choose("Choose what to do:", "100 Run", "1K Runs", "Run max 10K with confidence", "Back");
|
||||||
|
var seed = Rng.newSeed();
|
||||||
|
var csv = "run" + seed + ".csv";
|
||||||
switch (choice) {
|
switch (choice) {
|
||||||
case 1 -> new SimulationBuilder(net).setMaxRuns(100).setParallel(true).run();
|
case 1 -> new SimulationBuilder(net).setSeed(seed).setMaxRuns(100).setParallel(true).setCsv(csv).run();
|
||||||
case 2 -> new SimulationBuilder(net).setMaxRuns(1000).setParallel(true).run();
|
case 2 -> new SimulationBuilder(net).setSeed(seed).setMaxRuns(1000).setParallel(true).setCsv(csv).run();
|
||||||
case 3 -> {
|
case 3 -> new SimulationBuilder(net).setSeed(seed).setMaxRuns(1000).setParallel(true).setCsv(csv).run();
|
||||||
var randName = "rand" + System.currentTimeMillis() + ".csv";
|
case 4 -> {
|
||||||
new SimulationBuilder(net).setMaxRuns(1000).setParallel(true).setCsv(randName).run();
|
var indices = ask("Confidence indices with format [node:stat=confidence:relativeError];[..]\n");
|
||||||
new Plot(randName).show();
|
new SimulationBuilder(net).setSeed(seed).setMaxRuns(10000).parseConfidenceIndices(indices).setCsv(csv)
|
||||||
new File(randName).delete();
|
.run();
|
||||||
}
|
}
|
||||||
default -> {
|
default -> {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ public class Plot {
|
|||||||
var frame = new JFrame("Graph of the Simulation");
|
var frame = new JFrame("Graph of the Simulation");
|
||||||
frame.add(rootPane);
|
frame.add(rootPane);
|
||||||
frame.setSize(800, 600);
|
frame.setSize(800, 600);
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,4 +131,13 @@ public class Rng {
|
|||||||
var t = multiplier * (seed % Q) - R * (seed / Q);
|
var t = multiplier * (seed % Q) - R * (seed / Q);
|
||||||
return t > 0 ? t : (t + modulus);
|
return t > 0 ? t : (t + modulus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This creates a new seed based on the current time.
|
||||||
|
*
|
||||||
|
* @return a new seed
|
||||||
|
*/
|
||||||
|
public static long newSeed() {
|
||||||
|
return System.currentTimeMillis() % MODULUS;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -146,5 +146,4 @@ public class SimulationMultiple {
|
|||||||
stream.println(); // remove last printed line
|
stream.println(); // remove last printed line
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user