Skip to content

Commit

Permalink
update the StateVariables in KM
Browse files Browse the repository at this point in the history
  • Loading branch information
Rima_a authored and Rima_a committed Sep 22, 2014
1 parent 9295852 commit 55cb945
Show file tree
Hide file tree
Showing 12 changed files with 632 additions and 8 deletions.
19 changes: 19 additions & 0 deletions jdeeco-core/src/cz/cuni/mff/d3s/deeco/annotations/Asynch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cz.cuni.mff.d3s.deeco.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
*
* @author Rima Al Ali
*
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Asynch {
String[] names();
String parent() default "";
}

19 changes: 19 additions & 0 deletions jdeeco-core/src/cz/cuni/mff/d3s/deeco/annotations/Sets.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cz.cuni.mff.d3s.deeco.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
*
* @author Rima Al Ali
*
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Sets {
Asynch[] asynch() default {};
Synch[] synch() default {};
}

19 changes: 19 additions & 0 deletions jdeeco-core/src/cz/cuni/mff/d3s/deeco/annotations/Synch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cz.cuni.mff.d3s.deeco.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
*
* @author Rima Al Ali
*
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Synch {
String[] names();
String parent() default "";
}

Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void execute(Task task, Trigger trigger) {
Transition transition = ProcessConditionParser.returnTransitions(componentInstance,km, process);
if(transition != null){
// System.out.println(".....................................................................reset........"+transition);
ProcessConditionParser.resetTransitions(componentInstance,process,transition);
ProcessConditionParser.resetTransitions(km,componentInstance,process,transition);
}

if(process.isIsRunning()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import org.eclipse.emf.common.util.EList;
import org.mvel2.MVEL;

import cz.cuni.mff.d3s.deeco.knowledge.ChangeSet;
import cz.cuni.mff.d3s.deeco.knowledge.KnowledgeManager;
import cz.cuni.mff.d3s.deeco.knowledge.KnowledgeNotFoundException;
import cz.cuni.mff.d3s.deeco.knowledge.KnowledgeUpdateException;
import cz.cuni.mff.d3s.deeco.knowledge.ValueSet;
import cz.cuni.mff.d3s.deeco.model.runtime.RuntimeModelHelper;
import cz.cuni.mff.d3s.deeco.model.runtime.api.ComponentInstance;
Expand Down Expand Up @@ -191,7 +193,7 @@ public static void initStates(ComponentInstance componentInstance) {
}
}

public static void resetTransitions(ComponentInstance componentInstance,
public static void resetTransitions(KnowledgeManager km, ComponentInstance componentInstance,
ComponentProcess process, Transition transition) {
transition.setIsReachable(false);
process.setIsRunning(true);
Expand All @@ -203,6 +205,22 @@ public static void resetTransitions(ComponentInstance componentInstance,
setNextTransitions(componentInstance,process, transition);

setFromRunning(process);
setKnowledge(km,componentInstance);
}

private static void setKnowledge(KnowledgeManager km,
ComponentInstance componentInstance) {
ChangeSet vs = new ChangeSet();
for (ComponentProcess cProcess : componentInstance.getComponentProcesses()) {
KnowledgePath kp = RuntimeModelHelper.createKnowledgePath(cProcess.getName());
vs.setValue(kp, cProcess.isIsRunning());
}
try {
km.update(vs);
} catch (KnowledgeUpdateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

private static void filterSilbing(ComponentInstance componentInstance,
Expand Down
16 changes: 10 additions & 6 deletions tester/src/demo_annotation/test/FullExample/Helicopter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

import java.util.HashMap;
import cz.cuni.mff.d3s.deeco.annotations.Component;
import cz.cuni.mff.d3s.deeco.annotations.Field;
import cz.cuni.mff.d3s.deeco.annotations.In;
import cz.cuni.mff.d3s.deeco.annotations.InOut;
import cz.cuni.mff.d3s.deeco.annotations.Model;
import cz.cuni.mff.d3s.deeco.annotations.Out;
import cz.cuni.mff.d3s.deeco.annotations.PeriodicScheduling;
import cz.cuni.mff.d3s.deeco.annotations.Process;
import cz.cuni.mff.d3s.deeco.annotations.State;
import cz.cuni.mff.d3s.deeco.annotations.Sets;
import cz.cuni.mff.d3s.deeco.annotations.Asynch;
import cz.cuni.mff.d3s.deeco.annotations.Synch;
import cz.cuni.mff.d3s.deeco.annotations.StateSpaceModel;
import cz.cuni.mff.d3s.deeco.annotations.TimeStamp;
import cz.cuni.mff.d3s.deeco.annotations.TriggerOnTimeStampChange;
Expand All @@ -21,6 +23,8 @@


@StateSpaceModel(models = {@Model( period = 100, state = {"hFFPos","hFFSpeed"}, referenceModel = VehicleModel.class)})
@Sets(asynch = @Asynch(names = {"NoSearch","RequestSearch"}, parent = "NoSelfSearch"),
synch = @Synch(names = {"SelfSearch","NoSelfSearch"}))
@Component
public class Helicopter {

Expand Down Expand Up @@ -65,7 +69,7 @@ public Helicopter(String name, Double pos) {
hFFTargetPos = pos;
}

@State(param = @Field(name = "hFFPos", guard = "organizeSearch && V > 0 && LH > 10"))
@State(set = "NoSearch", guard = "organizeSearch && V > 0 && LH > 10")
@Process
@PeriodicScheduling((int) TIMEPERIOD)
public static void initilizedSystem(
Expand All @@ -84,7 +88,7 @@ public static void initilizedSystem(
}

//I can mediate for another
// @State(param = @Field(name = "hSearch_In", guard = "initilizedSystem && V == hID"))
@State(set = "RequestSearch", guard = "initilizedSystem && V == hID")
@Process
public static void toldToSearch(
@In("hSearch_In") @TriggerOnTimeStampChange String hSearch_In,
Expand All @@ -101,7 +105,7 @@ public static void toldToSearch(
hFFTargetSpeed.value = hSpeed;
}

@State(param = @Field( name = "hFFPos", guard = {"V > 0","initilizedSystem && V > 0","organizeSearch && LH <= 5"}))
@State(set = "NoSearch", guard = {"V > 0","initilizedSystem && V > 0","organizeSearch && LH <= 5"})
@Process
public static void mediate(
@InOut("hFFPos") @TriggerOnTimeStampChange InaccuracyParamHolder<Double> hFFPos,
Expand All @@ -116,7 +120,7 @@ public static void mediate(
hFFTargetSpeed.value = hSpeed;
}

@State(param = {@Field(name = "hFFPos", guard = "V > 0 && LH > 5")})
@State(set = "NoSearch", guard = "V > 0 && LH > 5")
@Process
public static void otherSearch(
@In("hID") String hID,
Expand Down Expand Up @@ -144,7 +148,7 @@ public static void otherSearch(
}


@State(param = {@Field(name = "hFFPos", guard = "V > 0 && LH > 5")})
@State(set = "SelfSearch", guard = "V > 0 && LH > 5")
@Process
public static void leadSearch(
@In("hID") String hID,
Expand Down
194 changes: 194 additions & 0 deletions tester/src/demo_annotation/test/Modes/complete/Database.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
package demo_annotation.test.Modes.complete;

import java.util.ArrayList;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.math3.analysis.UnivariateFunction;
import org.apache.commons.math3.analysis.interpolation.LinearInterpolator;
import org.apache.commons.math3.analysis.interpolation.UnivariateInterpolator;

public class Database {

protected static final ArrayList<Double> driverSpeed = new ArrayList<Double>();
protected static final ArrayList<Double> routeSlops = new ArrayList<Double>();
protected static final ArrayList<Double> fTorques = new ArrayList<Double>();
protected static final ArrayList<Double> lTorques = new ArrayList<Double>();
public static final ArrayList<Double> hTorques = new ArrayList<Double>();
protected static final ArrayList<Double> positionSeries = new ArrayList<Double>();
protected static final ArrayList<Double> speedSeries = new ArrayList<Double>();
protected static final ArrayList<Double> rotationSeries = new ArrayList<Double>();
protected static final ArrayList<Double> helicopterSpeedSeries = new ArrayList<Double>();
protected static final ArrayList<Double> helicopterArea = new ArrayList<Double>();
protected static final double lMass = 1000;
protected static final double fMass = 1000;
public static final double hMass = 5;
protected static final double r_density = 1000; // depends on the temperature of air, altitude, and humidity.
protected static final double C_L = 0.5;
protected static final double C_D = 0.00005;
protected static final double r = 0.5;
protected static final double c = 0.2;
protected static final double g = 9.80665;

static{
positionSeries.add(-10000.0);
positionSeries.add(0.0);
positionSeries.add(1000.0);
positionSeries.add(2000.0);
positionSeries.add(3000.0);
positionSeries.add(4000.0);
positionSeries.add(5000.0);
positionSeries.add(6000.0);
positionSeries.add(7000.0);
positionSeries.add(8000.0);
positionSeries.add(9000.0);
positionSeries.add(10000.0);
positionSeries.add(100000.0);

driverSpeed.add(0.0);
driverSpeed.add(90.0);
driverSpeed.add(90.0);
driverSpeed.add(90.0);
driverSpeed.add(/*150*/90.0);
driverSpeed.add(/*170*/90.0);
driverSpeed.add(90.0);
driverSpeed.add(90.0);
driverSpeed.add(90.0);
driverSpeed.add(90.0);
driverSpeed.add(90.0);
driverSpeed.add(90.0);
driverSpeed.add(90.0);

routeSlops.add(0.0);
routeSlops.add(0.0);
routeSlops.add(0.0);
routeSlops.add(/*Math.PI/60*/0.0);
routeSlops.add(/*Math.PI/30*/0.0);
routeSlops.add(/*Math.PI/20*/0.0);
routeSlops.add(/*Math.PI/15*/0.0);
routeSlops.add(0.0);
routeSlops.add(0.0);
routeSlops.add(/*-Math.PI/18*/0.0);
routeSlops.add(/*-Math.PI/36*/0.0);
routeSlops.add(0.0);
routeSlops.add(0.0);


speedSeries.add(-100000.0);
speedSeries.add(0.0);
speedSeries.add(8.0);
speedSeries.add(20.0);
speedSeries.add(28.0);
speedSeries.add(40.0);
speedSeries.add(60.0);
speedSeries.add(80.0);
speedSeries.add(100.0);
speedSeries.add(120.0);
speedSeries.add(140.0);
speedSeries.add(160.0);
speedSeries.add(180.0);
speedSeries.add(200.0);
speedSeries.add(220.0);

helicopterSpeedSeries.add(-100000.0);
helicopterSpeedSeries.add(0.0);
helicopterSpeedSeries.add(8.0);
helicopterSpeedSeries.add(20.0);
helicopterSpeedSeries.add(28.0);
helicopterSpeedSeries.add(40.0);
helicopterSpeedSeries.add(60.0);
helicopterSpeedSeries.add(80.0);
helicopterSpeedSeries.add(100.0);
helicopterSpeedSeries.add(120.0);
helicopterSpeedSeries.add(160.0);
helicopterSpeedSeries.add(200.0);
helicopterSpeedSeries.add(300.0);
helicopterSpeedSeries.add(400.0);
helicopterSpeedSeries.add(100000.0);

rotationSeries.add(2*Math.PI/60);
rotationSeries.add(2*Math.PI/60);
rotationSeries.add(12*Math.PI/60);
rotationSeries.add(25*Math.PI/60);
rotationSeries.add(32*Math.PI/60);
rotationSeries.add(40*Math.PI/60);
rotationSeries.add(49*Math.PI/60);
rotationSeries.add(58*Math.PI/60);
rotationSeries.add(65*Math.PI/60);
rotationSeries.add(73*Math.PI/60);
rotationSeries.add(80*Math.PI/60);
rotationSeries.add(85*Math.PI/60);
rotationSeries.add(90*Math.PI/60);
rotationSeries.add(95*Math.PI/60);
rotationSeries.add(96*Math.PI/60);

helicopterArea.add(1.600);
helicopterArea.add(1.616);
helicopterArea.add(1.640);
helicopterArea.add(1.656);
helicopterArea.add(1.720);
helicopterArea.add(1.760);
helicopterArea.add(1.800);
helicopterArea.add(1.840);
helicopterArea.add(1.880);
helicopterArea.add(1.920);
helicopterArea.add(2.000);
helicopterArea.add(2.400);
helicopterArea.add(2.800);
helicopterArea.add(3.200);
helicopterArea.add(3.500);

lTorques.add(0.0);
lTorques.add(165.0);
lTorques.add(180.0);
lTorques.add(180.0);
lTorques.add(170.0);
lTorques.add(170.0);
lTorques.add(150.0);
lTorques.add(115.0);
lTorques.add(97.0);
lTorques.add(80.0);
lTorques.add(70.0);
lTorques.add(60.0);
lTorques.add(50.0);
lTorques.add(40.0);
lTorques.add(1.0);

fTorques.addAll(lTorques);
hTorques.addAll(lTorques);

}

public static Double getAcceleration(Double speed, Double pos, ArrayList<Double> torques,Double gas, Double brake, Double mass){
double FEng = gas * getValue(speedSeries, torques, speed) / 0.005;
double FResistance = brake * 10000;
double FEngResistance = 0.0005 * speed;
double FHill = Math.sin(getValue(positionSeries, routeSlops, pos)) * g * mass;
double FFinal = FEng - FResistance - FEngResistance - FHill;
double Acceleration = FFinal / mass;

return Acceleration;
}


public static Double getHelicopterAcceleration(Double speed, Double pos, ArrayList<Double> rotations,Double gas, Double brake, Double mass){
double w = gas * getValue(helicopterSpeedSeries, rotations, speed);
double A = brake * getValue(helicopterSpeedSeries, helicopterArea, speed);
double FL = (r_density / 2) * C_L * Math.pow( w * r ,2) * 4 * r * c;
double FResistance = (r_density / 2) * C_D * Math.pow(speed, 2) * A;
double FFinal = FL - FResistance;
double Acceleration = FFinal / mass;

return Acceleration;
}

public static Double getValue(ArrayList<Double> x, ArrayList<Double> y, Double key){
double a[] = ArrayUtils.toPrimitive(x.toArray(new Double[x.size()]));
double b[] = ArrayUtils.toPrimitive(y.toArray(new Double[y.size()]));
UnivariateInterpolator interpolator = new LinearInterpolator();//Spline interpolation more accurate
UnivariateFunction function = interpolator.interpolate(a,b);
if(key < 0.0) key = 0.0;
if(key > 220.0) key = 220.0;
double value = function.value(key);
return value;
}
}
Loading

0 comments on commit 55cb945

Please sign in to comment.