Commit db340255 authored by Matias Richart's avatar Matias Richart
Browse files

working on rate and power

parent 8e613be7
......@@ -5,6 +5,7 @@ import java.util.HashSet;
import java.util.Set;
import uy.edu.fing.mina.fsa.tf.CompositeTf;
import uy.edu.fing.mina.fsa.tf.Operator;
import uy.edu.fing.mina.fsa.tf.SimpleTf;
import uy.edu.fing.mina.fsa.tf.TfI;
import uy.edu.fing.mina.fsa.tffst.State;
......@@ -68,12 +69,34 @@ public class RateAndPower_LuPA {
//-------------------------------------------------------------
//not low | | high | decrease | keep
//not low | | not high | keep | increase
//low | | increase | keep | keep
//low | | | keep | keep
EventTf ll = new EventTf();
ll.setName("ll");
EventTf ml = new EventTf();
ml.setName("ml");
EventTf hl = new EventTf();
hl.setName("hl");
EventTf lp = new EventTf();
lp.setName("lp");
EventTf mp = new EventTf();
mp.setName("mp");
EventTf hp = new EventTf();
hp.setName("hp");
ActionTf kr = new ActionTf();
kr.setName("kr");
kr.setUniverse("rate");
ActionTf dr = new ActionTf();
dr.setName("dr");
dr.setUniverse("rate");
ActionTf ip = new ActionTf();
ip.setName("ip");
ip.setUniverse("power");
......@@ -82,22 +105,13 @@ public class RateAndPower_LuPA {
dp.setName("dp");
dp.setUniverse("power");
EventTf hl = new EventTf();
hl.setName("hl");
EventTf lp = new EventTf();
lp.setName("lp");
EventTf ml = new EventTf();
ml.setName("ml");
EventTf mp = new EventTf();
mp.setName("mp");
ActionTf kp = new ActionTf();
kp.setName("kp");
kp.setUniverse("power");
// rules.add(rap.ruleTemplate((new SimpleTf("ll")).not() , SimpleTf.Epsilon(),(new SimpleTf("hp")) , new SimpleTf("dr"), new SimpleTf("kp")));
// rules.add(rap.ruleTemplate((new SimpleTf("ll")).not() , SimpleTf.Epsilon(),(new SimpleTf("hp")).not() , new SimpleTf("kr"), new SimpleTf("ip")));
// rules.add(rap.ruleTemplate((new SimpleTf("ll")) , SimpleTf.Epsilon(),(new SimpleTf("pi")) , new SimpleTf("kr"), new SimpleTf("kp")));
/* rules.add(rap.ruleTemplate(ll.not(), EventTf.Epsilon(), hp, dr, kp));
rules.add(rap.ruleTemplate(ll.not(), EventTf.Epsilon(),hp.not(), kr, ip));
rules.add(rap.ruleTemplate(ll, EventTf.Epsilon(), EventTf.Epsilon(), kr, kp));*/
//-----------------------------------------------------------
......@@ -106,7 +120,8 @@ public class RateAndPower_LuPA {
// rules.add(rap.ruleTemplate((new SimpleTf("ml")) , SimpleTf.Epsilon(),(new SimpleTf("lp")) , new SimpleTf("kr"), new SimpleTf("ip")));
rules.add(rap.ruleTemplate(hl, EventTf.Epsilon(),lp , ip.not(), new CompositeTf("AND",ip,kr.not())));
//rules.add(rap.ruleTemplate(new CompositeTf(Operator.AND,hl,ml), EventTf.Epsilon(),lp , ip.not(), (new CompositeTf(Operator.AND,ip,kr.not())).not()));
rules.add(rap.ruleTemplate(hl, EventTf.Epsilon(),lp , ip.not(), kr));
//rules.add(rap.ruleTemplate(ml, SimpleTf.Epsilon(),mp , kr, new CompositeTf("AND", ip, new CompositeTf("AND",kr,dp))));
// rules.add(rap.ruleTemplate((new SimpleTf("hl")) , SimpleTf.Epsilon(),(new SimpleTf("mp")) , new SimpleTf("kr"), new SimpleTf("ip")));
// rules.add(rap.ruleTemplate((new SimpleTf("ll")) , SimpleTf.Epsilon(),(new SimpleTf("pi")) , new SimpleTf("kr"), new SimpleTf("kp")));
......@@ -137,14 +152,14 @@ public class RateAndPower_LuPA {
rateAndPower = rateAndPower.union(tffst);
}
//Utils.showDot(rateAndPower.toDot("before"));
Utils.showDot(rateAndPower.toDot("before"));
//rateAndPower.setDeterministic(false);
//rateAndPower.determinize();
rateAndPower.setDeterministic(false);
rateAndPower.determinize();
//rateAndPower = rateAndPower.kleene();
rateAndPower = rateAndPower.kleene();
//Utils.showDot(rateAndPower.toDot("after"));
Utils.showDot(rateAndPower.toDot("after"));
try {
LupaExporterRatePower.generateLupaFiles(rateAndPower, "src/fsm_template.lua", "out_test_pdp_aux");
......
......@@ -212,7 +212,15 @@ public class LupaExporterRatePower {
private static void loadEvents(TfI tfi) throws UnsupportedTFFSTException{
String functionName = functionName(tfi);
if(tfi instanceof CompositeTf){
compositeEvents.put(functionName, tfi);
if(tfi.isNot()){
compositeEvents.put(functionName,tfi);
tfi = tfi.not();
functionName = functionName(tfi);
compositeEvents.put(functionName, tfi);
}
else{
compositeEvents.put(functionName, tfi);
}
loadEvents(((CompositeTf) tfi).left);
loadEvents(((CompositeTf) tfi).right);
}
......@@ -404,15 +412,41 @@ public class LupaExporterRatePower {
String functionHeader;
for(String functionName : mainActions.keySet()){
functionHeader = functionHeader(functionName);
// There are no duplicates in a Map.
if(! out.contains(functionHeader)){
out = out.concat("\t-- " + functionHeader + "\n");
out = out.concat("actions." + functionName + " = function(e)\n");
// TODO Mejorar!!
out = out.concat("\te = shared[\"incomming_event\"]\n");
if (((ActionTf)mainActions.get(functionName)).getUniverse().compareTo("rate") == 0){
out = out.concat("\tlocal levels = getDomain('rate')\n");
out = out.concat("\tlocal retMax = -100\n");
out = out.concat("\tlocal l\n");
out = out.concat("\tfor _,lr in ipairs(levels) do\n");
out = out.concat("\t\tlocal ret = functions." + functionName + "(lr)\n");
out = out.concat("\t\tif ret > retMax then\n" +
"\t\t\tretMax = ret\n" +
"\t\t\tl = lr\n" +
"\t\tend\n" +
"\tend\n" +
"\treturn notifs.changeRate(l,e)\n" +
"end\n");
}
else{
out = out.concat("\tlocal levels = getDomain('power')\n");
out = out.concat("\tlocal retMax = -100\n");
out = out.concat("\tlocal l\n");
out = out.concat("\tfor _,lp in ipairs(levels) do\n");
out = out.concat("\t\tlocal ret = functions." + functionName + "(lp)\n");
out = out.concat("\t\tif ret > retMax then\n" +
"\t\t\tretMax = ret\n" +
"\t\t\tl = lp\n" +
"\t\tend\n" +
"\tend\n" +
"\treturn notifs.changePower(l,e)\n" +
"end\n");
}
out = out.concat("\t-- " + functionHeader + "\n");
out = out.concat("functions." + functionName + " = function(e)\n");
out = out.concat("\t------------------------------------------------\n");
out = out.concat("\t-- TODO: Complete this with your action code. --\n");
out = out.concat("\t-- TODO: Complete this with your function code. --\n");
out = out.concat("\t------------------------------------------------\n");
out = out.concat("end\n\n");
}
......@@ -439,7 +473,16 @@ public class LupaExporterRatePower {
String functionName;
for(TfI function : compositeEvents.values()){
functionName = functionName(function);
if(function instanceof CompositeTf){
if (function.isNot()) {
out = out.concat("-- " + function.getName() + "\n");
out = out.concat("events." + functionName + " = function(e) \n");
TfI nonneg = function.not();
out = out.concat("\tlocal nonneg = events." + functionName(nonneg) + "(e)\n");
out = out.concat("\treturn 1-nonneg\n");
out = out.concat("end\n");
}
else if(function instanceof CompositeTf){
comp = (CompositeTf) function;
leftTf = comp.left;
rightTf = comp.right;
......@@ -455,14 +498,6 @@ public class LupaExporterRatePower {
}
out = out.concat("end\n");
}
else if (function.isNot()) {
out = out.concat("-- " + function.getName() + "\n");
out = out.concat("events." + functionName + " = function(e) \n");
TfI nonneg = function.not();
out = out.concat("\tlocal nonneg = events." + functionName(nonneg) + "(e)\n");
out = out.concat("\treturn 1-nonneg\n");
out = out.concat("end\n");
}
else{
throw new UnsupportedTFFSTException("A problematic function (" + function.getName() +") was detected. A generated EVENT function should always be composite or not.");
}
......@@ -494,6 +529,7 @@ public class LupaExporterRatePower {
String functionName;
for (Entry<String, ArrayList<ArrayList<TfI>>> item : compositeActions.entrySet()) {
functionName = item.getKey();
out = out.concat("-- " + functionName + "\n");
out = out.concat("actions." + functionName + " = function(e)\n");
ArrayList<TfI> compositeActionsRate = item.getValue().get(0);
ArrayList<TfI> compositeActionsPower = item.getValue().get(1);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment