Commit bb18ee0c authored by Stephan Korsholm's avatar Stephan Korsholm
Browse files

Resolve "Simulating Active links with Additional Loss"

Showing with 100 additions and 4 deletions
+100 -4
......@@ -316,7 +316,9 @@ public class GenericSystemSimulation implements SimulationInstance {
Interferer simulateInterferenceLink(InterferenceLink link, LinkResult iLink, AntennaEnvironment rxEnv,
AntennaEnvironment txEnv, String ilrName, String iltName, Point2D terrainReferencePoint, int eventNumber) {
itTrial(iLink);
iLink.setActivity(link.getCorrelationSettings());
if (eventNumber != 0) {
iLink.setActivity(link.getCorrelationSettings());
}
if (probe.shouldSkipSimulationIfNotActive() && !iLink.isActive()) {
skipSimulation(iLink);
} else {
......
......@@ -70,6 +70,12 @@ public class DeterministicWorkspaceLoader {
});
}
private SimulationPool pool;
protected void stopSimulation() {
pool.getPool().shutdownNow();
}
protected EventResult runSimulation(final long seed, Consumer<SingleResult> collector, Runnable beginSimulation) {
final EventResult[] lastEvent = new EventResult[1];
WorkspaceScenario workspaceScenario = new WorkspaceScenario(workspace);
......@@ -97,7 +103,6 @@ public class DeterministicWorkspaceLoader {
fixSeedInSimulationEngine(calculateEventSeed(simulationSeed, eventNumber));
}
};
SimulationPool pool;
if (runSimulationSynchronously()) {
pool = new SimulationPool(1);
} else {
......
......@@ -327,6 +327,64 @@ public class TestFixedPosition extends DeterministicWorkspaceLoader {
InterferenceSimulationEngine.unregisterSimulationStartListener(listener);
}
@Test
public void testFixedDistributionsWithActiveTransmitters() throws Exception {
final InterferenceSimulationEngine[] engine = new InterferenceSimulationEngine[1];
loadWorkspace("/Benchmark_ws_Activity_2_90__OFF_AF_jpk_NotWork.sws");
TestUtil.setActivityFactor(workspace, 1.0d, "Link 1 (ISL - Generic)");
final long start = System.currentTimeMillis();
System.out.println("Starting simulation with full activity");
workspace.setNumberOfEvents(50);
runSimulation(1L, new TestUtil.SimulationProgressReporter(10, "simulation tick"));
final long end = System.currentTimeMillis();
final long time = end - start;
System.out.println("Took " + time + " ms");
loadWorkspace("/Benchmark_ws_Activity_2_90__OFF_AF_jpk_NotWork.sws");
TestUtil.setActivityFactor(workspace, 0.5d, "Link 1 (ISL - Generic)");
WaitThread waitThread = new WaitThread(time);
waitThread.start();
System.out.println("Restarting simulation with 0.5 activity factor");
workspace.setNumberOfEvents(50);
runSimulation(1L, new TestUtil.SimulationProgressReporter(10, "simulation tick"));
waitThread.setStop();
waitThread.join();
}
private class WaitThread extends Thread {
private final long waitTime;
private volatile boolean stop;
public WaitThread(long waitTime) {
this.waitTime = waitTime;
this.stop = false;
}
public void setStop() {
this.stop = true;
}
@Override
public void run() {
long rerunStart = System.currentTimeMillis();
long currentTime = rerunStart;
while (currentTime - rerunStart < waitTime + 5000) {
try {
System.out.println(
"Waiting for simulation to finish [" + (currentTime - rerunStart) + ", " + waitTime + "]");
Thread.sleep(1000);
} catch (InterruptedException ignore) {
}
currentTime = System.currentTimeMillis();
if (stop) {
System.out.println("Told to stop waiting");
return;
}
}
stopSimulation();
fail("Simulation took more than " + (currentTime - rerunStart) + " ms, which indicates a deadlock");
}
}
@Test
@Ignore
public void testFixedDistributionForMultipleTransmitters() throws Exception {
......
......@@ -4,9 +4,11 @@ import static org.junit.Assert.assertTrue;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.function.Consumer;
import org.seamcat.model.InterferenceLinkElement;
import org.seamcat.model.correlation.ActiveTransmitters;
import org.seamcat.model.distributions.Distribution;
import org.seamcat.model.engines.SingleResult;
import org.seamcat.model.factory.ProxyHelper;
import org.seamcat.model.plugin.system.SystemPlugin;
import org.seamcat.model.systems.generic.GenericSystemPlugin;
......@@ -57,6 +59,15 @@ public class TestUtil {
}
}
public static void setNumberOfActiveTransmitters(Workspace workspace, int v, String linkName) throws Exception {
activeTransmitterSetting(workspace, new Integer(v), "activeTx", linkName);
}
public static void setActivityFactor(Workspace workspace, double factor, String linkName) throws Exception {
activeTransmitterSetting(workspace, new Double(factor), "probability", linkName);
}
private static <T> void activeTransmitterSetting(Workspace workspace, T value, String methodName, String linkName)
throws Exception {
for (InterferenceLinkElement le : workspace.getInterferenceLinkUIs()) {
if (le.getName().contains(linkName)) {
ActiveTransmitters iluis =
......@@ -65,8 +76,8 @@ public class TestUtil {
Map<Method, Object> values = ProxyHelper.getProxyValues(iluis);
for (Method m : values.keySet()) {
if (m.getName().contains("activeTx")) {
values.put(m, new Integer(v));
if (m.getName().contains(methodName)) {
values.put(m, value);
return;
}
}
......@@ -74,4 +85,24 @@ public class TestUtil {
}
throw new Exception("Link name not found: " + linkName);
}
public static class SimulationProgressReporter implements Consumer<SingleResult> {
private final String message;
private int tickCount;
private int granularity;
public SimulationProgressReporter(int granularity, String message) {
this.tickCount = 0;
this.granularity = granularity;
this.message = message;
}
@Override
public void accept(SingleResult singleResult) {
tickCount++;
if (tickCount % granularity == 0) {
System.out.println(message);
}
}
}
}
File added
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment