From bf46d9ad3fd5234a99b6e247d85115d55f048b05 Mon Sep 17 00:00:00 2001 From: Ralf Sieger Date: Sat, 11 Jan 2025 12:55:16 +0100 Subject: [PATCH] basic in-process simulation working --- .../META-INF/MANIFEST.MF | 7 +++- .../ea/launch/EAOptimizerLaunchFactory.java | 10 +++-- .../local/LocalEAFitnessEvaluator.java | 39 +++++++++++++++++-- .../ISimExpWorkflowConfiguration.java | 2 +- .../config/SimExpWorkflowConfiguration.java | 1 + .../launcher/SimulationExecutorLookup.java | 2 +- 6 files changed, 51 insertions(+), 10 deletions(-) rename bundles/org.palladiosimulator.simexp.workflow/src/main/java/org/palladiosimulator/simexp/workflow/{config => api}/ISimExpWorkflowConfiguration.java (92%) diff --git a/bundles/org.palladiosimulator.simexp.dsl.ea.launch/META-INF/MANIFEST.MF b/bundles/org.palladiosimulator.simexp.dsl.ea.launch/META-INF/MANIFEST.MF index 41dbb344..5b3dfad2 100644 --- a/bundles/org.palladiosimulator.simexp.dsl.ea.launch/META-INF/MANIFEST.MF +++ b/bundles/org.palladiosimulator.simexp.dsl.ea.launch/META-INF/MANIFEST.MF @@ -4,7 +4,8 @@ Bundle-ManifestVersion: 2 Bundle-Name: org.palladiosimulator.simexp.dsl.ea.launch Bundle-Vendor: My Company Bundle-Version: 0.1.0.qualifier -Require-Bundle: org.apache.log4j;bundle-version="1.2.19", +Require-Bundle: org.eclipse.core.runtime;bundle-version="3.26.100", + org.apache.log4j;bundle-version="1.2.19", org.palladiosimulator.simexp.workflow;bundle-version="1.0.0", tools.mdsd.probdist.api;bundle-version="1.0.0", org.palladiosimulator.simexp.pcm;bundle-version="1.0.0", @@ -16,7 +17,9 @@ Require-Bundle: org.apache.log4j;bundle-version="1.2.19", org.palladiosimulator.simexp.dsl.ea.api;bundle-version="0.1.0", org.palladiosimulator.simexp.dsl.ea.optimizer;bundle-version="0.1.0", org.palladiosimulator.simexp.dsl.smodel.api;bundle-version="0.1.0", - org.palladiosimulator.simexp.dsl.smodel.interpreter;bundle-version="0.1.0" + org.palladiosimulator.simexp.dsl.smodel.interpreter;bundle-version="0.1.0", + org.palladiosimulator.simexp.pcm.modelled.simulator;bundle-version="1.0.0", + org.palladiosimulator.simexp.pcm.simulator;bundle-version="1.0.0" Bundle-SymbolicName: org.palladiosimulator.simexp.dsl.ea.launch;singleton:=true Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-17 diff --git a/bundles/org.palladiosimulator.simexp.dsl.ea.launch/src/main/java/org/palladiosimulator/simexp/dsl/ea/launch/EAOptimizerLaunchFactory.java b/bundles/org.palladiosimulator.simexp.dsl.ea.launch/src/main/java/org/palladiosimulator/simexp/dsl/ea/launch/EAOptimizerLaunchFactory.java index cbca8acd..77c6d82a 100644 --- a/bundles/org.palladiosimulator.simexp.dsl.ea.launch/src/main/java/org/palladiosimulator/simexp/dsl/ea/launch/EAOptimizerLaunchFactory.java +++ b/bundles/org.palladiosimulator.simexp.dsl.ea.launch/src/main/java/org/palladiosimulator/simexp/dsl/ea/launch/EAOptimizerLaunchFactory.java @@ -12,6 +12,7 @@ import org.palladiosimulator.simexp.pcm.config.IModelledWorkflowConfiguration; import org.palladiosimulator.simexp.pcm.config.IWorkflowConfiguration; import org.palladiosimulator.simexp.pcm.examples.executor.ModelLoader; +import org.palladiosimulator.simexp.pcm.examples.executor.ModelLoader.Factory; import org.palladiosimulator.simexp.pcm.modelled.ModelledModelLoader; import org.palladiosimulator.simexp.workflow.api.ILaunchFactory; import org.palladiosimulator.simexp.workflow.api.LaunchDescriptionProvider; @@ -43,12 +44,15 @@ public SimulationExecutor createSimulationExecutor(IWorkflowConfiguration config IModelledWorkflowConfiguration modelledWorkflowConfiguration = (IModelledWorkflowConfiguration) config; URI smodelURI = modelledWorkflowConfiguration.getSmodelURI(); Smodel smodel = modelledModelLoader.loadSModel(smodelURI); - IDisposeableEAFitnessEvaluator fitnessEvaluator = createFitnessEvaluator(modelledWorkflowConfiguration); + IDisposeableEAFitnessEvaluator fitnessEvaluator = createFitnessEvaluator(modelledWorkflowConfiguration, + launchDescriptionProvider, seedProvider, modelLoaderFactory); return new EAOptimizerSimulationExecutor(smodel, fitnessEvaluator); } - private IDisposeableEAFitnessEvaluator createFitnessEvaluator(IModelledWorkflowConfiguration config) { - return new LocalEAFitnessEvaluator(); + private IDisposeableEAFitnessEvaluator createFitnessEvaluator(IModelledWorkflowConfiguration config, + LaunchDescriptionProvider launchDescriptionProvider, Optional seedProvider, + Factory modelLoaderFactory) { + return new LocalEAFitnessEvaluator(config, launchDescriptionProvider, seedProvider, modelLoaderFactory); } } diff --git a/bundles/org.palladiosimulator.simexp.dsl.ea.launch/src/main/java/org/palladiosimulator/simexp/dsl/ea/launch/evaluate/local/LocalEAFitnessEvaluator.java b/bundles/org.palladiosimulator.simexp.dsl.ea.launch/src/main/java/org/palladiosimulator/simexp/dsl/ea/launch/evaluate/local/LocalEAFitnessEvaluator.java index b4d54d0d..edf2ec5b 100644 --- a/bundles/org.palladiosimulator.simexp.dsl.ea.launch/src/main/java/org/palladiosimulator/simexp/dsl/ea/launch/evaluate/local/LocalEAFitnessEvaluator.java +++ b/bundles/org.palladiosimulator.simexp.dsl.ea.launch/src/main/java/org/palladiosimulator/simexp/dsl/ea/launch/evaluate/local/LocalEAFitnessEvaluator.java @@ -1,6 +1,7 @@ package org.palladiosimulator.simexp.dsl.ea.launch.evaluate.local; import java.util.List; +import java.util.Optional; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -8,14 +9,33 @@ import java.util.concurrent.TimeUnit; import org.apache.log4j.Logger; +import org.eclipse.core.runtime.CoreException; +import org.palladiosimulator.core.simulation.SimulationExecutor; import org.palladiosimulator.simexp.dsl.ea.launch.evaluate.IDisposeableEAFitnessEvaluator; +import org.palladiosimulator.simexp.pcm.config.IModelledWorkflowConfiguration; +import org.palladiosimulator.simexp.pcm.examples.executor.ModelLoader.Factory; +import org.palladiosimulator.simexp.workflow.api.ISimExpWorkflowConfiguration; +import org.palladiosimulator.simexp.workflow.api.LaunchDescriptionProvider; +import org.palladiosimulator.simexp.workflow.launcher.SimulationExecutorLookup; + +import tools.mdsd.probdist.api.random.ISeedProvider; public class LocalEAFitnessEvaluator implements IDisposeableEAFitnessEvaluator { protected static final Logger LOGGER = Logger.getLogger(LocalEAFitnessEvaluator.class); + private final IModelledWorkflowConfiguration config; + private final LaunchDescriptionProvider launchDescriptionProvider; + private final Optional seedProvider; + private final Factory modelLoaderFactory; private final ExecutorService executor; - public LocalEAFitnessEvaluator() { + public LocalEAFitnessEvaluator(IModelledWorkflowConfiguration config, + LaunchDescriptionProvider launchDescriptionProvider, Optional seedProvider, + Factory modelLoaderFactory) { + this.config = config; + this.launchDescriptionProvider = launchDescriptionProvider; + this.seedProvider = seedProvider; + this.modelLoaderFactory = modelLoaderFactory; this.executor = Executors.newFixedThreadPool(1); } @@ -41,8 +61,21 @@ public Double call() throws Exception { return future; } - private Double doCalcFitness(List> optimizableValues) { + private Double doCalcFitness(List> optimizableValues) throws CoreException { + SimulationExecutorLookup simulationExecutorLookup = new SimulationExecutorLookup(); + SimulationExecutor effectiveSimulationExecutor = simulationExecutorLookup + .lookupSimulationExecutor((ISimExpWorkflowConfiguration) config, launchDescriptionProvider, seedProvider); + + LOGGER.info("effective simulation start"); + try { + effectiveSimulationExecutor.execute(); + effectiveSimulationExecutor.evaluate(); + } finally { + effectiveSimulationExecutor.dispose(); + } + LOGGER.info("effective simulation finish"); + // TODO: - return null; + return 0.0; } } diff --git a/bundles/org.palladiosimulator.simexp.workflow/src/main/java/org/palladiosimulator/simexp/workflow/config/ISimExpWorkflowConfiguration.java b/bundles/org.palladiosimulator.simexp.workflow/src/main/java/org/palladiosimulator/simexp/workflow/api/ISimExpWorkflowConfiguration.java similarity index 92% rename from bundles/org.palladiosimulator.simexp.workflow/src/main/java/org/palladiosimulator/simexp/workflow/config/ISimExpWorkflowConfiguration.java rename to bundles/org.palladiosimulator.simexp.workflow/src/main/java/org/palladiosimulator/simexp/workflow/api/ISimExpWorkflowConfiguration.java index b9738e92..64d189c7 100644 --- a/bundles/org.palladiosimulator.simexp.workflow/src/main/java/org/palladiosimulator/simexp/workflow/config/ISimExpWorkflowConfiguration.java +++ b/bundles/org.palladiosimulator.simexp.workflow/src/main/java/org/palladiosimulator/simexp/workflow/api/ISimExpWorkflowConfiguration.java @@ -1,4 +1,4 @@ -package org.palladiosimulator.simexp.workflow.config; +package org.palladiosimulator.simexp.workflow.api; import org.palladiosimulator.simexp.pcm.config.IModelledPrismWorkflowConfiguration; import org.palladiosimulator.simexp.pcm.config.IModelledWorkflowConfiguration; diff --git a/bundles/org.palladiosimulator.simexp.workflow/src/main/java/org/palladiosimulator/simexp/workflow/config/SimExpWorkflowConfiguration.java b/bundles/org.palladiosimulator.simexp.workflow/src/main/java/org/palladiosimulator/simexp/workflow/config/SimExpWorkflowConfiguration.java index f16d04ae..85b9dcfc 100644 --- a/bundles/org.palladiosimulator.simexp.workflow/src/main/java/org/palladiosimulator/simexp/workflow/config/SimExpWorkflowConfiguration.java +++ b/bundles/org.palladiosimulator.simexp.workflow/src/main/java/org/palladiosimulator/simexp/workflow/config/SimExpWorkflowConfiguration.java @@ -11,6 +11,7 @@ import org.palladiosimulator.simexp.commons.constants.model.SimulationEngine; import org.palladiosimulator.simexp.commons.constants.model.SimulatorType; import org.palladiosimulator.simexp.pcm.config.SimulationParameters; +import org.palladiosimulator.simexp.workflow.api.ISimExpWorkflowConfiguration; import tools.mdsd.probdist.api.random.ISeedProvider; diff --git a/bundles/org.palladiosimulator.simexp.workflow/src/main/java/org/palladiosimulator/simexp/workflow/launcher/SimulationExecutorLookup.java b/bundles/org.palladiosimulator.simexp.workflow/src/main/java/org/palladiosimulator/simexp/workflow/launcher/SimulationExecutorLookup.java index 87ec54c2..b89bdb85 100644 --- a/bundles/org.palladiosimulator.simexp.workflow/src/main/java/org/palladiosimulator/simexp/workflow/launcher/SimulationExecutorLookup.java +++ b/bundles/org.palladiosimulator.simexp.workflow/src/main/java/org/palladiosimulator/simexp/workflow/launcher/SimulationExecutorLookup.java @@ -13,8 +13,8 @@ import org.eclipse.core.runtime.Platform; import org.palladiosimulator.core.simulation.SimulationExecutor; import org.palladiosimulator.simexp.workflow.api.ILaunchFactory; +import org.palladiosimulator.simexp.workflow.api.ISimExpWorkflowConfiguration; import org.palladiosimulator.simexp.workflow.api.LaunchDescriptionProvider; -import org.palladiosimulator.simexp.workflow.config.ISimExpWorkflowConfiguration; import tools.mdsd.probdist.api.random.ISeedProvider;