import mecsyco.core.agent.EventMAgent; import mecsyco.core.coupling.CentralizedEventCouplingArtifact; import mecsyco.core.exception.CausalityException; public class Launcher { public final static double maxSimulationTime = 10; public static void main(String args[]) { /**********************************/ /**** AGENTS & MODEL ARTEFACTS ****/ /**********************************/ // First agent with first model (model1) EventMAgent agent1 = new EventMAgent("Name1",maxSimulationTime); MyModel1Artefact ModelArtefact1 = new MyModel1Artefact(); agent1.setModelArtefact(ModelArtefact1); // Second agent with second model (model2) EventMAgent agent2 = new EventMAgent("Name2",maxSimulationTime); MyModel2Artefact ModelArtefact2 = new MyModel2Artefact(); agent2.setModelArtefact(ModelArtefact2); /****************************/ /**** COUPLING ARTEFACTS ****/ /****************************/ // Model1 Model2 // .--------------. .--------------. // | .---. .---. .---. .---. | // | | y |------| y |<-------| Y |------| Y | | // | '---' '---' '---' '---' | // | | | | // | .---. .---. .---. .---. | // | | X |------| X |------->| x |------| x | | // | '---' '---' '---' '---' | // '--------------' '--------------' // // "y" and "X" are model1's state variables (typed Double) // "Y" and "x" are model2's state variables (typed Double) // We consider that the port names correspond to the state variable with which they are linked // During the simulation, X and Y are exchanged and models states are modified, // with model1.y = model2.Y and model2.x = model1.X CentralizedEventCouplingArtifact couplingFrom1To2 = new CentralizedEventCouplingArtifact(); CentralizedEventCouplingArtifact couplingFrom2To1 = new CentralizedEventCouplingArtifact(); // Agent1 will update "y" with the value received from couplingFrom2To1 (input events) // Agent2 will update "x" with the value received from couplingFrom1To2 (input events) agent1.addInputCouplingArtifact(couplingFrom2To1, "y"); agent2.addInputCouplingArtifact(couplingFrom1To2, "x"); // Agent1 will send "X" to couplingFrom1To2 (output events) // Agent2 will send "Y" to couplingFrom2To1 (output events) agent1.addOutputCouplingArtifact(couplingFrom1To2, "X"); agent2.addOutputCouplingArtifact(couplingFrom2To1, "Y"); /*******************************/ /**** MODELS INITIALIZATION ****/ /*******************************/ // Start the simulation softwares associated to model1 and model2 // This is not systematically necessary, it depends on the simulation software used agent1.startModelSoftware(); agent2.startModelSoftware(); // Initialize model1 and model2 parameters // e.g. time discretization or constants // This is not systematically necessary, it depends on the model String [] args_model1 = { "0.001" }; String [] args_model2 = { "0.01" }; agent1.setModelParameters(args_model1); agent2.setModelParameters(args_model2); /***************************************/ /**** CO-SIMULATION INIT & STARTING ****/ /***************************************/ try { // Co-initialization with first exchanges // This is necessary only when the model initial states are co-dependent agent1.coInitialize(); agent2.coInitialize(); // Start the co-simulation agent1.start(); agent2.start(); // This should never happen } catch (CausalityException e) { e.printStackTrace(); } } }