package simulator
The Kompics Simulator DSL for Scala
case object SimpleSimulation { import Distributions._ // needed for the distributions, but needs to be initialised after setting the seed implicit val random = JSimulationScenario.getRandom(); private def intToAddress(i: Int): Address = { try { new TAddress(new InetSocketAddress(InetAddress.getByName("192.193.0." + i), 10000)); } catch { case ex: UnknownHostException => throw new RuntimeException(ex); } } val startResultSetterOp = Op { (self: Integer) => val selfAddr = intToAddress(self); StartNode(selfAddr, Init[ResultSetter](selfAddr)) }; val startPongerOp = Op { (self: Integer) => val selfAddr = intToAddress(self) StartNode(selfAddr, Init[PongerParent](selfAddr)) }; val startPingerOp = Op { (self: Integer, ponger: Integer) => val selfAddr = intToAddress(self); val pongerAddr = intToAddress(ponger); StartNode(selfAddr, Init[PingerParent](selfAddr, pongerAddr)) }; val scenario = raise(5, startPongerOp, 1.toN) .arrival(constant(1000.millis)) .andThen(1000.millis) .afterTermination(raise(5, startPingerOp, 6.toN, 1.toN).arrival(constant(1000.millis))) .inParallel(raise(1, startResultSetterOp, 1.toN).arrival(constant(1000.millis))) .andThen(10000.millis) .afterTermination(Terminate); }
- Alphabetic
- By Inheritance
- simulator
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
- implicit class IntDistributions extends AnyRef
Allow the creation of BasicIntSequentialDistribution via
i.toN()
- class StochasticProcess extends AnyRef
A sequence of operations with a distribution of time between them
- class StochasticProcessBuilder extends AnyRef
A builder class for StochasticProcess instances
- class StochasticProcessChain extends Serializable
A simulation is formed by a chain of stochastic processes
A simulation is formed by a chain of stochastic processes
It should end with a Terminate process.
- See also
se.sics.kompics.sl.simulator for an example
Value Members
- implicit def chainToScenario(spc: StochasticProcessChain): SimulationScenario
Automatically convert a StochasticProcessChain into a SimulationScenario
Automatically convert a StochasticProcessChain into a SimulationScenario
- spc
the original process chain
- returns
the new simulation scenario
- See also
- def raise[E <: KompicsEvent, N <: Number, N2 <: Number, N3 <: Number, N4 <: Number, N5 <: Number](count: Int, op: Operation5[E, N, N2, N3, N4, N5], d: Distribution[N], d2: Distribution[N2], d3: Distribution[N3], d4: Distribution[N4], d5: Distribution[N5]): StochasticProcessBuilder
Raise a number of events produced by an operation
Raise a number of events produced by an operation
- E
the type of event to produce
- N
the type of the first operation argument
- N2
the type of the second operation argument
- N3
the type of the third operation argument
- N4
the type of the fourth operation argument
- N5
the type of the fifth operation argument
- count
the number of events produce
- op
the operation that creates the events
- d
the distribution for the first operation argument
- d2
the distribution for the second operation argument
- d3
the distribution for the third operation argument
- d4
the distribution for the fourth operation argument
- d5
the distribution for the fifth operation argument
- returns
a new StochasticProcessBuilder with the raise operation appended
- def raise[E <: KompicsEvent, N <: Number, N2 <: Number, N3 <: Number, N4 <: Number](count: Int, op: Operation4[E, N, N2, N3, N4], d: Distribution[N], d2: Distribution[N2], d3: Distribution[N3], d4: Distribution[N4]): StochasticProcessBuilder
Raise a number of events produced by an operation
Raise a number of events produced by an operation
- E
the type of event to produce
- N
the type of the first operation argument
- N2
the type of the second operation argument
- N3
the type of the third operation argument
- N4
the type of the fourth operation argument
- count
the number of events produce
- op
the operation that creates the events
- d
the distribution for the first operation argument
- d2
the distribution for the second operation argument
- d3
the distribution for the third operation argument
- d4
the distribution for the fourth operation argument
- returns
a new StochasticProcessBuilder with the raise operation appended
- def raise[E <: KompicsEvent, N <: Number, N2 <: Number, N3 <: Number](count: Int, op: Operation3[E, N, N2, N3], d: Distribution[N], d2: Distribution[N2], d3: Distribution[N3]): StochasticProcessBuilder
Raise a number of events produced by an operation
Raise a number of events produced by an operation
- E
the type of event to produce
- N
the type of the first operation argument
- N2
the type of the second operation argument
- N3
the type of the third operation argument
- count
the number of events produce
- op
the operation that creates the events
- d
the distribution for the first operation argument
- d2
the distribution for the second operation argument
- d3
the distribution for the third operation argument
- returns
a new StochasticProcessBuilder with the raise operation appended
- def raise[E <: KompicsEvent, N <: Number, N2 <: Number](count: Int, op: Operation2[E, N, N2], d: Distribution[N], d2: Distribution[N2]): StochasticProcessBuilder
Raise a number of events produced by an operation
Raise a number of events produced by an operation
- E
the type of event to produce
- N
the type of the first operation argument
- N2
the type of the second operation argument
- count
the number of events produce
- op
the operation that creates the events
- d
the distribution for the first operation argument
- d2
the distribution for the second operation argument
- returns
a new StochasticProcessBuilder with the raise operation appended
- def raise[E <: KompicsEvent, N <: Number](count: Int, op: Operation1[E, N], d: Distribution[N]): StochasticProcessBuilder
Raise a number of events produced by an operation
Raise a number of events produced by an operation
- E
the type of event to produce
- N
the type of the first operation argument
- count
the number of events produce
- op
the operation that creates the events
- d
the distribution for the first operation argument
- returns
a new StochasticProcessBuilder with the raise operation appended
- def raise[E <: KompicsEvent](count: Int, op: Operation[E]): StochasticProcessBuilder
Raise a number of events produced by an operation
Raise a number of events produced by an operation
- E
the type of event to produce
- count
the number of events produce
- op
the operation that creates the events
- returns
a new StochasticProcessBuilder with the raise operation appended
- implicit def stochasticProcessToChain(sp: StochasticProcess): StochasticProcessChain
Automatically convert a StochasticProcess to a StochasticProcessChain
Automatically convert a StochasticProcess to a StochasticProcessChain
- sp
the starting process of the chain
- returns
the new chain
- See also
- object ChangeNetwork
Construct instances of se.sics.kompics.simulator.events.system.ChangeNetworkModelEvent
- object Distributions
Convenience DSL objects for building different kinds of distributions.
- object KillNode
Construct instances of se.sics.kompics.simulator.events.system.KillNodeEvent
- object Op
Operations of various arities, which produce a KompicsEvent
Operations of various arities, which produce a KompicsEvent
Arities from zero to five are provided.
Use these to map parameters to simulator events using the various raise functions.
raise(5, Op { (self: Integer, other: Integer) => val selfAddr = lookupAddress(self); /* Get an address instance for the id */ val otherAddr = lookupAddress(ponger); /* Get an address instance for the id */ StartNode(selfAddr, Init[NewComponent](selfAddr, otherAddr)) }, 1.toN, 2.toN)
- See also
Example: - object Setup
Construct setup events
Construct setup events
- object SimulationResult
A helper to share values between the simluation and the testing code
A helper to share values between the simluation and the testing code
Since simulations run with a different classloader than the code that spawns them, it is usually difficult to share values between them. This class allows doing so, using a string-indexed map.
The underlying implementation is se.sics.kompics.simulator.result.SimulationResultSingleton.
SimulationResult += ("test" -> 1); /* Pass 1 to the simulation */ SimpleSimulation.scenario.simulate(classOf[LauncherComp]); /* The simulation runs and sets "test" to 2 */ SimulationResult[Int]("test") should be(2); /* Get the new value from the simulation */
Example: - object StartNode
Utilities to start a node in a simulation
Utilities to start a node in a simulation
All of them are simply conveniences to create an instance of se.sics.kompics.simulator.events.system.StartNodeEvent.
- object Terminate extends StochasticProcess with Product with Serializable
A special process that marks the end of the simulation