CE Uebungen und Folien
This commit is contained in:
parent
cd375c0afe
commit
7ba5dfb091
BIN
ws2012/CE/Folien/gms-02-NAE-col.pdf
Normal file
BIN
ws2012/CE/Folien/gms-02-NAE-col.pdf
Normal file
Binary file not shown.
BIN
ws2012/CE/Folien/gms-03-NAE-col.pdf
Normal file
BIN
ws2012/CE/Folien/gms-03-NAE-col.pdf
Normal file
Binary file not shown.
BIN
ws2012/CE/Folien/gms-04-NAE-col.pdf
Normal file
BIN
ws2012/CE/Folien/gms-04-NAE-col.pdf
Normal file
Binary file not shown.
BIN
ws2012/CE/uebungen/0/EiCE_Uebung_00b.pdf
Normal file
BIN
ws2012/CE/uebungen/0/EiCE_Uebung_00b.pdf
Normal file
Binary file not shown.
BIN
ws2012/CE/uebungen/1/EiCE_Uebung01.pdf
Normal file
BIN
ws2012/CE/uebungen/1/EiCE_Uebung01.pdf
Normal file
Binary file not shown.
BIN
ws2012/CE/uebungen/1/EiCE_Uebung01_Solution_Lukas.pdf
Normal file
BIN
ws2012/CE/uebungen/1/EiCE_Uebung01_Solution_Lukas.pdf
Normal file
Binary file not shown.
2119
ws2012/CE/uebungen/1/petrinetz.graphml
Normal file
2119
ws2012/CE/uebungen/1/petrinetz.graphml
Normal file
File diff suppressed because it is too large
Load Diff
BIN
ws2012/CE/uebungen/1/petrinetz.jpg
Normal file
BIN
ws2012/CE/uebungen/1/petrinetz.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 151 KiB |
BIN
ws2012/CE/uebungen/1/solution.odt
Normal file
BIN
ws2012/CE/uebungen/1/solution.odt
Normal file
Binary file not shown.
BIN
ws2012/CE/uebungen/1/solution.pdf
Normal file
BIN
ws2012/CE/uebungen/1/solution.pdf
Normal file
Binary file not shown.
BIN
ws2012/CE/uebungen/2/EiCE_Uebung02.pdf
Normal file
BIN
ws2012/CE/uebungen/2/EiCE_Uebung02.pdf
Normal file
Binary file not shown.
BIN
ws2012/CE/uebungen/2/uebung02_solution.odt
Normal file
BIN
ws2012/CE/uebungen/2/uebung02_solution.odt
Normal file
Binary file not shown.
BIN
ws2012/CE/uebungen/2/uebung02_solution.pdf
Normal file
BIN
ws2012/CE/uebungen/2/uebung02_solution.pdf
Normal file
Binary file not shown.
BIN
ws2012/CE/uebungen/3/02_20051116_dsi.pdf
Normal file
BIN
ws2012/CE/uebungen/3/02_20051116_dsi.pdf
Normal file
Binary file not shown.
BIN
ws2012/CE/uebungen/3/7.Komplexe Zahlen.pdf
Normal file
BIN
ws2012/CE/uebungen/3/7.Komplexe Zahlen.pdf
Normal file
Binary file not shown.
BIN
ws2012/CE/uebungen/3/EiCE_Uebung03_update.pdf
Normal file
BIN
ws2012/CE/uebungen/3/EiCE_Uebung03_update.pdf
Normal file
Binary file not shown.
BIN
ws2012/CE/uebungen/3/Merkzettel - Nichtlineare Systeme.pdf
Normal file
BIN
ws2012/CE/uebungen/3/Merkzettel - Nichtlineare Systeme.pdf
Normal file
Binary file not shown.
BIN
ws2012/CE/uebungen/3/uebung03_solution.odt
Normal file
BIN
ws2012/CE/uebungen/3/uebung03_solution.odt
Normal file
Binary file not shown.
BIN
ws2012/CE/uebungen/3/uebung03_solution.pdf
Normal file
BIN
ws2012/CE/uebungen/3/uebung03_solution.pdf
Normal file
Binary file not shown.
Binary file not shown.
6
ws2012/CE/uebungen/P1/DEVS/.classpath
Normal file
6
ws2012/CE/uebungen/P1/DEVS/.classpath
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
17
ws2012/CE/uebungen/P1/DEVS/.project
Normal file
17
ws2012/CE/uebungen/P1/DEVS/.project
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>DEVS2</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@ -0,0 +1,12 @@
|
||||
#Thu Oct 11 22:30:59 CEST 2012
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.5
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.5
|
||||
BIN
ws2012/CE/uebungen/P1/DEVS/bin/edu/eice2012/DEVS$StopEvent.class
Normal file
BIN
ws2012/CE/uebungen/P1/DEVS/bin/edu/eice2012/DEVS$StopEvent.class
Normal file
Binary file not shown.
BIN
ws2012/CE/uebungen/P1/DEVS/bin/edu/eice2012/DEVS.class
Normal file
BIN
ws2012/CE/uebungen/P1/DEVS/bin/edu/eice2012/DEVS.class
Normal file
Binary file not shown.
BIN
ws2012/CE/uebungen/P1/DEVS/bin/edu/eice2012/DEVSMain.class
Normal file
BIN
ws2012/CE/uebungen/P1/DEVS/bin/edu/eice2012/DEVSMain.class
Normal file
Binary file not shown.
BIN
ws2012/CE/uebungen/P1/DEVS/bin/edu/eice2012/DiscreteEvent.class
Normal file
BIN
ws2012/CE/uebungen/P1/DEVS/bin/edu/eice2012/DiscreteEvent.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
ws2012/CE/uebungen/P1/DEVS/bin/edu/eice2012/MyExponential.class
Normal file
BIN
ws2012/CE/uebungen/P1/DEVS/bin/edu/eice2012/MyExponential.class
Normal file
Binary file not shown.
BIN
ws2012/CE/uebungen/P1/DEVS/bin/edu/eice2012/MyNormalDist.class
Normal file
BIN
ws2012/CE/uebungen/P1/DEVS/bin/edu/eice2012/MyNormalDist.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
ws2012/CE/uebungen/P1/DEVS/bin/edu/eice2012/QueueDEVS.class
Normal file
BIN
ws2012/CE/uebungen/P1/DEVS/bin/edu/eice2012/QueueDEVS.class
Normal file
Binary file not shown.
Binary file not shown.
117
ws2012/CE/uebungen/P1/DEVS/src/edu/eice2012/DEVS.java
Normal file
117
ws2012/CE/uebungen/P1/DEVS/src/edu/eice2012/DEVS.java
Normal file
@ -0,0 +1,117 @@
|
||||
/**
|
||||
Vorlesung: Einfuehrung in Computational Engineering
|
||||
@author Arne Naegel
|
||||
@date Oktober 2012
|
||||
*/
|
||||
|
||||
package edu.eice2012;
|
||||
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.PriorityQueue;
|
||||
|
||||
/* This class implements a time dependent discrete event simulation */
|
||||
abstract public class DEVS {
|
||||
|
||||
// GENERAL
|
||||
protected PriorityQueue<DiscreteEvent> queue;
|
||||
private double time;
|
||||
private double maxTime;
|
||||
|
||||
// CONSTRUCTOR
|
||||
public DEVS(){
|
||||
queue = new PriorityQueue<DiscreteEvent>(2);
|
||||
time = 0.0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected class StopEvent extends DiscreteEvent{
|
||||
StopEvent(double t) {
|
||||
super(t,'X');
|
||||
}
|
||||
}
|
||||
|
||||
// USER-DEFINED FUNCTIONS
|
||||
/** This routine may be implemented */
|
||||
public void initialize() {
|
||||
queue.add(new StopEvent(maxTime));
|
||||
}
|
||||
|
||||
/** This routine must be implemented */
|
||||
abstract public void eventRoutine(DiscreteEvent ev);
|
||||
|
||||
/** This routine may be implemented */
|
||||
public void statistics() {}
|
||||
|
||||
|
||||
|
||||
// GENERAL FUNCTIONS
|
||||
/** getter time */
|
||||
public double getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
/** setter time */
|
||||
public void setTime(double time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
/** getter max time */
|
||||
public double getMaxTime() {
|
||||
return maxTime;
|
||||
}
|
||||
|
||||
/** setter max time */
|
||||
public void setMaxTime(double time) {
|
||||
this.maxTime = time;
|
||||
}
|
||||
|
||||
|
||||
/** Simulation stops if time limit has been reached*/
|
||||
public boolean stopCondition() {
|
||||
return getTime() > getMaxTime();
|
||||
}
|
||||
|
||||
/** Perform simulation run (event loop) */
|
||||
public void simulate(){
|
||||
|
||||
while (true){
|
||||
|
||||
// get event
|
||||
DiscreteEvent ev = queue.poll();
|
||||
|
||||
// abort, if queue is empty
|
||||
if (ev==null) {
|
||||
System.out.println("Queue is empty!");
|
||||
break;
|
||||
}
|
||||
|
||||
// update time and treat event
|
||||
time = ev.getTime();
|
||||
eventRoutine(ev);
|
||||
|
||||
// print queue status
|
||||
System.out.print("{");
|
||||
|
||||
for (Iterator<DiscreteEvent> it = queue.iterator(); it.hasNext();)
|
||||
{
|
||||
System.out.print(it.next()+", ");
|
||||
}
|
||||
System.out.println("}");
|
||||
|
||||
// check for stop condition
|
||||
if (ev instanceof StopEvent)
|
||||
{
|
||||
System.out.println("Terminating");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
50
ws2012/CE/uebungen/P1/DEVS/src/edu/eice2012/DEVSMain.java
Normal file
50
ws2012/CE/uebungen/P1/DEVS/src/edu/eice2012/DEVSMain.java
Normal file
@ -0,0 +1,50 @@
|
||||
/**
|
||||
Vorlesung: Einfuehrung in Computational Engineering
|
||||
@author Arne Naegel
|
||||
@date Oktober 2012
|
||||
*/
|
||||
|
||||
package edu.eice2012;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class DEVSMain {
|
||||
|
||||
/** execute program */
|
||||
public static void main(String args[]){
|
||||
|
||||
// create random number generator
|
||||
RandomNumberGenerator randA;
|
||||
RandomNumberGenerator randD;
|
||||
double maxtime;
|
||||
|
||||
// ALTERNATIVE 1: results from exercise 1
|
||||
// TODO: VAlidierung in Aufgabenteil b)
|
||||
randA = new MyExponential();
|
||||
randD = new MyNormalDist();
|
||||
maxtime = 100.0;
|
||||
|
||||
|
||||
// ALTERNATIVE 2: 'real' random numbers
|
||||
// TODO: Experimente in Aufgabenteil d)
|
||||
/* Random r = new Random(47);
|
||||
|
||||
|
||||
randA = new ExponentialDistributionWrapper(r, 5.0);
|
||||
randD = new ExponentialDistributionWrapper(r, 6.0);
|
||||
//randD= new NormalDistributionWrapper(r, 6.0, 2.0);
|
||||
maxtime = 20000;
|
||||
*/
|
||||
|
||||
DEVS sim = new QueueDEVS(randA, randD);
|
||||
|
||||
sim.setMaxTime(maxtime);
|
||||
sim.initialize();
|
||||
sim.simulate();
|
||||
|
||||
sim.statistics();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
/**
|
||||
Vorlesung: Einfuehrung in Computational Engineering
|
||||
@author Arne Naegel
|
||||
@date Oktober 2012
|
||||
*/
|
||||
package edu.eice2012;
|
||||
|
||||
import java.lang.Double;
|
||||
|
||||
public class DiscreteEvent implements Comparable<DiscreteEvent>{
|
||||
|
||||
private double time;
|
||||
private char type;
|
||||
|
||||
|
||||
DiscreteEvent(double t, char c) {time=t; type=c;}
|
||||
|
||||
public double getTime() {
|
||||
return time;
|
||||
}
|
||||
public void setTime(double time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public char getType() {
|
||||
return type;
|
||||
}
|
||||
public void setType(char type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
public String toString(){
|
||||
return "Event<"+type+", "+time+">";
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int compareTo(DiscreteEvent e) {
|
||||
return new Double(time).compareTo(e.getTime());
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
package edu.eice2012;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
/** Generiert Werte einer Exponentialverteilung */
|
||||
public class ExponentialDistributionWrapper implements RandomNumberGenerator {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private double lambda;
|
||||
private Random r;
|
||||
private boolean doInteger;
|
||||
|
||||
public ExponentialDistributionWrapper(Random r){
|
||||
this (r, 1.0);
|
||||
}
|
||||
|
||||
public ExponentialDistributionWrapper(Random r, double lambda){
|
||||
this.doInteger=false;
|
||||
this.r = r;
|
||||
this.lambda=lambda;
|
||||
}
|
||||
|
||||
|
||||
public double nextDoubleValue(){
|
||||
double x = r.nextDouble();
|
||||
if (doInteger) return (double) Math.round(-Math.log(1.0-x)/lambda);
|
||||
return -Math.log(1.0-x)/lambda;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
/**
|
||||
Vorlesung: Einfuehrung in Computational Engineering
|
||||
@author Arne Naegel
|
||||
@date Oktober 2012
|
||||
*/
|
||||
package edu.eice2012;
|
||||
|
||||
public class MyExponential implements RandomNumberGenerator
|
||||
|
||||
{
|
||||
MyExponential() {i=0;}
|
||||
|
||||
public double nextDoubleValue(){
|
||||
double val=data[i];
|
||||
i=(i+1)%data.length;
|
||||
return val;
|
||||
};
|
||||
|
||||
private int i;
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static double data[] =
|
||||
//{0.57, 2.73, 1.36, 0.72, 0.23, 0.08, 1.21, 0.35, 2.81, 0.19, 0.88};
|
||||
{8.76, 16.82, 15.40, 26.72,3.46,27.06,23.52,8.06,0.71,42.03,56.27};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
/**
|
||||
Vorlesung: Einfuehrung in Computational Engineering
|
||||
@author Arne Naegel
|
||||
@date Oktober 2012
|
||||
*/
|
||||
package edu.eice2012;
|
||||
|
||||
public class MyNormalDist implements RandomNumberGenerator
|
||||
|
||||
{
|
||||
MyNormalDist() {i=0;}
|
||||
|
||||
public double nextDoubleValue(){
|
||||
double val=data[i];
|
||||
i=(i+1)%data.length;
|
||||
return val;
|
||||
};
|
||||
|
||||
private int i;
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static double data[] =
|
||||
//{1.89, 2.02, 2.56, 3.84, 2.00, 2.28, 3.32, 3.56, 2.97, 2.67, 2.70};
|
||||
{25.30, 20.11, 13.25, 10.68, 16.85, 19.22, 23.96, 28.30, 24.55, 22.70, 17.14};
|
||||
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
package edu.eice2012;
|
||||
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
/** Generiert Werte einer Normalverteilung */
|
||||
public class NormalDistributionWrapper implements RandomNumberGenerator{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private double mu;
|
||||
private double sigma;
|
||||
private Random r;
|
||||
private boolean doInteger; // returning integers or doubles?
|
||||
|
||||
|
||||
public NormalDistributionWrapper(Random r){
|
||||
this(r, 0.0, 1.0);
|
||||
}
|
||||
|
||||
public NormalDistributionWrapper(Random r, double mu, double sigma){
|
||||
this.r = r;
|
||||
this.mu=mu;
|
||||
this.sigma=sigma;
|
||||
this.doInteger=false;
|
||||
}
|
||||
|
||||
public double nextDoubleValue(){
|
||||
double x = r.nextGaussian();
|
||||
if (doInteger) return (double) Math.round( mu +x*sigma);
|
||||
return mu +x*sigma;
|
||||
}
|
||||
|
||||
}
|
||||
277
ws2012/CE/uebungen/P1/DEVS/src/edu/eice2012/QueueDEVS.java
Normal file
277
ws2012/CE/uebungen/P1/DEVS/src/edu/eice2012/QueueDEVS.java
Normal file
@ -0,0 +1,277 @@
|
||||
/**
|
||||
Vorlesung: Einfuehrung in Computational Engineering
|
||||
@author Arne Naegel
|
||||
@date Oktober 2012
|
||||
*/
|
||||
|
||||
package edu.eice2012;
|
||||
|
||||
import java.util.AbstractList;
|
||||
import java.util.Vector;
|
||||
|
||||
|
||||
public class QueueDEVS extends DEVS {
|
||||
|
||||
// problem specific variables
|
||||
private int server; // current machine state (0=idle)
|
||||
private int buffer; // current buffer length
|
||||
private int maxServers;
|
||||
|
||||
// random number generators
|
||||
private RandomNumberGenerator randA;
|
||||
private RandomNumberGenerator randD;
|
||||
|
||||
// statistics (per event)
|
||||
private Vector<Double> eventTimes; // time stamp when event is triggered
|
||||
private Vector<Character> eventTypes; // type of event
|
||||
private Vector<Double> serverList; // #items processed by server(s)
|
||||
private Vector<Double> bufferList; // #items in buffer
|
||||
private Vector<Double> loadList; // #items in system
|
||||
|
||||
|
||||
|
||||
/** Constructor */
|
||||
public QueueDEVS(RandomNumberGenerator randA, RandomNumberGenerator randD)
|
||||
{
|
||||
// attributes
|
||||
buffer = 0;
|
||||
server = 0;
|
||||
maxServers = 1;
|
||||
|
||||
// random numbers
|
||||
this.randA = randA;
|
||||
this.randD = randD;
|
||||
|
||||
|
||||
// statistics (per event)
|
||||
eventTimes = new Vector<Double>();
|
||||
eventTypes = new Vector<Character>();
|
||||
bufferList = new Vector<Double>();
|
||||
serverList = new Vector<Double>();
|
||||
loadList = new Vector<Double>();
|
||||
|
||||
// first entries
|
||||
eventTimes.add(0.0);
|
||||
eventTypes.add('I');
|
||||
bufferList.add(0.0);
|
||||
serverList.add(0.0);
|
||||
loadList.add(0.0);
|
||||
}
|
||||
|
||||
public void setRandomArrival(RandomNumberGenerator rand)
|
||||
{
|
||||
this.randA = rand;
|
||||
}
|
||||
|
||||
public void setRandomDeparture(RandomNumberGenerator rand)
|
||||
{
|
||||
this.randD = rand;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** status for server */
|
||||
public boolean allBusy()
|
||||
{
|
||||
return (server == maxServers);
|
||||
}
|
||||
|
||||
/** status for server */
|
||||
public boolean isIdle()
|
||||
{
|
||||
return (server==0);
|
||||
}
|
||||
|
||||
|
||||
public int getServerState() {
|
||||
return this.server;
|
||||
}
|
||||
|
||||
|
||||
public void initialize()
|
||||
{
|
||||
super.initialize();
|
||||
server = 0;
|
||||
buffer = 0;
|
||||
queue.add(new DiscreteEvent(0.5, 'A'));
|
||||
|
||||
/*
|
||||
* ALTERNATIVE: first arrival is random
|
||||
double offset = randA.nextDoubleValue();
|
||||
queue.add(new DiscreteEvent((offset), 'A'));
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
/** called for every event */
|
||||
public void eventRoutine(DiscreteEvent e)
|
||||
{
|
||||
|
||||
char type = e.getType();
|
||||
switch (type)
|
||||
{
|
||||
case 'A': arrivalRoutine(e); break;
|
||||
case 'D': departureRoutine(e); break;
|
||||
|
||||
default: System.out.println("Unknown event type -> Aborting!!!");
|
||||
};
|
||||
|
||||
|
||||
// print stats
|
||||
System.out.println("Event: "+e.getTime() + "|"+type+ "|"+ buffer+ "|"+ getServerState());
|
||||
|
||||
// record event statistics (example!)
|
||||
eventTimes.add(e.getTime()); // time stamp
|
||||
eventTypes.add(e.getType()); // type (A/D/X)
|
||||
int serverState = getServerState();
|
||||
serverList.add((double) serverState); // server state
|
||||
bufferList.add((double) buffer); // buffer state
|
||||
|
||||
int nItems = buffer + serverState;
|
||||
loadList.add((double) nItems); // system load
|
||||
};
|
||||
|
||||
/** TODO: called upon arrival */
|
||||
protected void arrivalRoutine (DiscreteEvent e)
|
||||
{
|
||||
|
||||
//System.out.println("arrivalRoutine muss implementiert werden!");
|
||||
|
||||
double offset1 = randA.nextDoubleValue();
|
||||
queue.add(new DiscreteEvent((getTime()+offset1), 'A'));
|
||||
|
||||
if(allBusy()){
|
||||
buffer++;
|
||||
}else{
|
||||
server++;
|
||||
double offset2 = randD.nextDoubleValue();
|
||||
queue.add(new DiscreteEvent(getTime()+offset2, 'D'));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/** TODO: called upon departure */
|
||||
protected void departureRoutine (DiscreteEvent e)
|
||||
{
|
||||
//System.out.println("departureRoutine muss implementiert werden!");
|
||||
|
||||
if(buffer == 0){
|
||||
server = 0;
|
||||
}else{
|
||||
buffer--;
|
||||
double offset=randD.nextDoubleValue();
|
||||
queue.add(new DiscreteEvent(getTime()+offset, 'D'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** aux: compute \sum v_i */
|
||||
static protected double firstMoments(AbstractList<Double> values){
|
||||
double val=0.0;
|
||||
int numEvents = values.size()-1;
|
||||
for (int i=0; i<numEvents; ++i)
|
||||
{
|
||||
val+=values.get(i);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
/** aux: compute \sum v_i * (t_{i+1}- t_{i})*/
|
||||
static protected double firstMoments(AbstractList<Double> values, AbstractList<Double> weights){
|
||||
double val=0.0;
|
||||
int numEvents = values.size()-1; // skip final STOP event!
|
||||
for (int i=0; i<numEvents; ++i)
|
||||
{
|
||||
double dt = weights.get(i+1)-weights.get(i);
|
||||
val+=values.get(i)*dt;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
/** aux: compute \sum v_i*v_i */
|
||||
static protected double secondMoments(AbstractList<Double> values){
|
||||
double val=0.0;
|
||||
int numEvents = values.size()-1; // skip final STOP event!
|
||||
for (int i=0; i<numEvents; ++i)
|
||||
{
|
||||
val+=values.get(i)*values.get(i);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
/** aux: compute \sum v_i * v_i * (t_{i+1}- t_{i})*/
|
||||
static protected double secondMoments(AbstractList<Double> values, AbstractList<Double> weights){
|
||||
double val=0.0;
|
||||
int numEvents = values.size()-1; // skip final STOP event!
|
||||
for (int i=0; i<numEvents; ++i)
|
||||
{
|
||||
double dt = weights.get(i+1)-weights.get(i);
|
||||
val+=values.get(i)*values.get(i)*dt;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
/** TODO:
|
||||
* aux: computes aggregated times T_k per load k
|
||||
* Hint: should be implemented analogously to firstMoments(AbstractList<Double>, AbstractList<Double>)
|
||||
* */
|
||||
static protected double[] aggregateTimesPerLoad(AbstractList<Double> times, AbstractList<Double> loads)
|
||||
{
|
||||
|
||||
int numEvents = loads.size()-1; // skip final STOP event!
|
||||
|
||||
// a) find maximum load
|
||||
int maxLoad = 0;
|
||||
for (int i=0; i<numEvents; ++i)
|
||||
{
|
||||
int load = (int) Math.round(loads.get(i));
|
||||
if (load > maxLoad) maxLoad = load;
|
||||
}
|
||||
|
||||
// b) compute sum of values and assign
|
||||
double val[] = new double[maxLoad+1];
|
||||
for (int i=0; i<numEvents; ++i)
|
||||
{
|
||||
int load = (int) Math.round(loads.get(i));
|
||||
double dt = times.get(i+1)-times.get(i);
|
||||
val[load] += dt;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void statistics()
|
||||
{
|
||||
|
||||
double time = getMaxTime();
|
||||
|
||||
|
||||
// example: statistics for system load
|
||||
double loadMoment1 = firstMoments(loadList, eventTimes);
|
||||
double loadMoment2 = secondMoments(loadList, eventTimes);
|
||||
double meanLoad= loadMoment1/time;
|
||||
double loadVar = (loadMoment2/time - (meanLoad)*(meanLoad));
|
||||
System.out.println("Mean system load: "+ meanLoad+" +/- "+Math.sqrt(loadVar));
|
||||
|
||||
// TODO: implement server usage
|
||||
System.out.println("Mean server usage: ??? +/- ???");
|
||||
|
||||
// times per system load
|
||||
double timeDist[] = aggregateTimesPerLoad(eventTimes, loadList);
|
||||
for (int k=0; k<timeDist.length; k++)
|
||||
{
|
||||
System.out.println("p["+k+"]="+timeDist[k]/time);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
package edu.eice2012;
|
||||
|
||||
/** Objects implementing this class generate a stream of numbers */
|
||||
public interface RandomNumberGenerator {
|
||||
|
||||
public double nextDoubleValue();
|
||||
}
|
||||
BIN
ws2012/CE/uebungen/P1/P1DEVS.zip
Normal file
BIN
ws2012/CE/uebungen/P1/P1DEVS.zip
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user