Commit a4ccedf0 authored by Javier Baliosian's avatar Javier Baliosian
Browse files

- Totalization fixed

- Complement fixed
parent 5508aaea
package uy.edu.fing.mina.fsa.test;
import java.util.ArrayList;
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;
import uy.edu.fing.mina.fsa.tffst.Tffst;
import uy.edu.fing.mina.fsa.tffst.Transition;
import uy.edu.fing.mina.fsa.utils.Utils;
import uy.edu.fing.mina.lupa.LupaExporter;
import uy.edu.fing.mina.lupa.LupaExporterRatePower;
import uy.edu.fing.mina.lupa.exceptions.UnsupportedTFFSTException;
import uy.edu.fing.mina.lupa.tf.ActionTf;
import uy.edu.fing.mina.lupa.tf.EventTf;
public class RateAndPower_nohalt_2 {
public Tffst ruleTemplate(TfI tfinp1,TfI tfinp2,TfI tfinp3,TfI tfout4,TfI tfout5) {
State s00 = new State();
State s01 = new State();
State s02 = new State();
State s03 = new State();
State s04 = new State();
State s05 = new State();
State s10 = new State();
State s11 = new State();
State s12 = new State();
State s13 = new State();
State s14 = new State();
State s15 = new State();
State s20 = new State();
State s21 = new State();
State s22 = new State();
State s23 = new State();
State s24 = new State();
State s25 = new State();
Tffst tffst0 = new Tffst();
tffst0.setInitialState(s00);
s05.setAccept(true);
Tffst tffst1 = new Tffst();
tffst1.setInitialState(s10);
s15.setAccept(true);
Tffst tffst2 = new Tffst();
tffst2.setInitialState(s20);
s25.setAccept(true);
s00.addOutTran(new Transition(tfinp1, ActionTf.Epsilon(),s01));
s00.addOutTran(new Transition(tfinp1.not(), ActionTf.Epsilon(),s00));
s01.addOutTran(new Transition(tfinp2, ActionTf.Epsilon(),s02));
s01.addOutTran(new Transition(tfinp2.not(), ActionTf.Epsilon(),s01));
s02.addOutTran(new Transition(tfinp3, ActionTf.Epsilon(),s03));
s02.addOutTran(new Transition(tfinp3.not(), ActionTf.Epsilon(),s02));
//----
s11.addOutTran(new Transition(tfinp2, ActionTf.Epsilon(),s12));
s11.addOutTran(new Transition(tfinp2.not(), ActionTf.Epsilon(),s11));
s12.addOutTran(new Transition(tfinp1, ActionTf.Epsilon(),s13));
s12.addOutTran(new Transition(tfinp1.not(), ActionTf.Epsilon(),s12));
s10.addOutTran(new Transition(tfinp3, ActionTf.Epsilon(),s11));
s10.addOutTran(new Transition(tfinp3.not(), ActionTf.Epsilon(),s10));
//-------
s22.addOutTran(new Transition(tfinp1, ActionTf.Epsilon(),s23));
s22.addOutTran(new Transition(tfinp1.not(), ActionTf.Epsilon(),s22));
s20.addOutTran(new Transition(tfinp2, ActionTf.Epsilon(),s21));
s20.addOutTran(new Transition(tfinp2.not(), ActionTf.Epsilon(),s20));
s21.addOutTran(new Transition(tfinp3, ActionTf.Epsilon(),s22));
s21.addOutTran(new Transition(tfinp3.not(), ActionTf.Epsilon(),s21));
s03.addOutTran(new Transition(EventTf.Epsilon(), tfout4,s04));
s04.addOutTran(new Transition(EventTf.Epsilon(), tfout5,s05));
s13.addOutTran(new Transition(EventTf.Epsilon(), tfout4,s14));
s14.addOutTran(new Transition(EventTf.Epsilon(), tfout5,s15));
s23.addOutTran(new Transition(EventTf.Epsilon(), tfout4,s24));
s24.addOutTran(new Transition(EventTf.Epsilon(), tfout5,s25));
tffst0.inLabelEpsilonRemoval();
tffst1.inLabelEpsilonRemoval();
tffst2.inLabelEpsilonRemoval();
// Utils.showDot(tffst0.toDot("tffst0"));
// Utils.showDot(tffst1.toDot("tffst1"));
// Utils.showDot(tffst2.toDot("tffst2"));
Tffst tffst = tffst0.union(tffst1).union(tffst2);
tffst.determinize();
// Utils.showDot(tffst.toDot("tffst"));
return tffst;
}
public static void main(String[] args) {
RateAndPower_nohalt_2 rap = new RateAndPower_nohalt_2();
Set<Tffst> rules = new HashSet<Tffst>();
// Inputs | Outputs
//-------------------------------------------------------------
//Loss | Rate | Power | Rate | Power
//-------------------------------------------------------------
//not low | | high | decrease | keep
//not low | | not high | keep | increase
//low | | | increase | 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");
EventTf lr = new EventTf();
lr.setName("lr");
EventTf hr = new EventTf();
hr.setName("hr");
ActionTf kr = new ActionTf();
kr.setName("kr");
kr.setUniverse("rate");
ActionTf dr = new ActionTf();
dr.setName("dr");
dr.setUniverse("rate");
ActionTf ir = new ActionTf();
ir.setName("ir");
ir.setUniverse("rate");
ActionTf ip = new ActionTf();
ip.setName("ip");
ip.setUniverse("power");
ActionTf dp = new ActionTf();
dp.setName("dp");
dp.setUniverse("power");
ActionTf kp = new ActionTf();
kp.setName("kp");
kp.setUniverse("power");
rules.add(rap.ruleTemplate(hl, EventTf.Epsilon(), hp, dr, kp));
rules.add(rap.ruleTemplate(hl, EventTf.Epsilon(),lp, kr, ip));
rules.add(rap.ruleTemplate(ll, EventTf.Epsilon(), EventTf.Epsilon(), ir, kp));
//Inputs | Outputs
// ---------------------------------------------------------------------
//Loss | Rate | Power | Rate | Power
// ---------------------------------------------------------------------
//not low | not low | | decrease | keep
//not low | low | high | keep | keep
//not low | low | not high | keep | increase
//low | | not low | keep | decrease
//low | high | low | keep | keep
//low | not high | low | increase | keep
rules.add(rap.ruleTemplate(hl ,hr ,EventTf.Epsilon(), dr, kp));
rules.add(rap.ruleTemplate(hl, lr, hp, kr, kp));
// rules.add(rap.ruleTemplate(hl, lr, lp, kr, ip));
// rules.add(rap.ruleTemplate(ll, EventTf.Epsilon(), hp, kr, dp));
// rules.add(rap.ruleTemplate(ll, hr, lp, kr, kp));
// rules.add(rap.ruleTemplate(ll, lr, lp, ir, kp));
Tffst rateAndPower = new Tffst();
for (Tffst tffst : rules) {
rateAndPower = rateAndPower.union(tffst);
}
// Utils.showDot(rateAndPower.toDot("before kleene"));
rateAndPower = rateAndPower.kleene();
// Utils.showDot(rateAndPower.toDot("before det"));
//
rateAndPower.setDeterministic(false);
rateAndPower.determinize();
//
// //Utils.showDot(rateAndPower.toDot("after all"));
//
// try {
// LupaExporterRatePower.generateLupaFiles(rateAndPower, "src/fsm_template.lua", "fsm_rate_loss");
// } catch (UnsupportedTFFSTException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
//
//
}
}
/*
* Created on 12-Aug-2004
*
* Copyright (C) 2004 Javier Baliosian
* All rights reserved.
* */
package uy.edu.fing.mina.fsa.test.operations;
import uy.edu.fing.mina.fsa.tf.SimpleTf;
import uy.edu.fing.mina.fsa.tf.TfI;
import uy.edu.fing.mina.fsa.tf.TfString;
import uy.edu.fing.mina.fsa.tffsr.State;
import uy.edu.fing.mina.fsa.tffsr.Tffsr;
import uy.edu.fing.mina.fsa.tffsr.Transition;
import uy.edu.fing.mina.fsa.utils.Utils;
/**
* @author Javier Baliosian &lt; <a
* href="mailto:jbaliosian@tsc.upc.es">jbaliosian@tsc.upc.es </a>&gt;
*/
public class TffsrToSingleLableTransitions {
/**
* uy.edu.fing.mina.omega.tffst.test 8. it shows determinization of a union
*
* @param args
*/
public static void main(String[] args) {
Tffsr tffsr1 = new Tffsr();
State s0 = new State();
tffsr1.setInitialState(s0);
State s1 = new State();
State s2 = new State();
s2.setAccept(true);
SimpleTf tfd = new SimpleTf("D");
SimpleTf tfb= new SimpleTf("B");
TfString label1 = new TfString(tfb); label1.add(tfd);
Transition trans1 = new Transition(label1, s1);
s0.addOutTran(trans1);
SimpleTf tfall = new SimpleTf();
tfall.setAcceptAll();
SimpleTf tfc = new SimpleTf();
tfc.setName("C");
TfI tfall_c = tfall.and(tfc.not());
Transition trans2 = new Transition(new TfString(tfall_c), s2);
s1.addOutTran(trans2);
SimpleTf tfk = new SimpleTf();
tfk.setName("K");
TfString sec = new TfString(tfc);
Transition trans3 = new Transition(sec, s2);
s1.addOutTran(trans3);
Utils.showDot(tffsr1.toDot("tffsr1"));
Tffsr tffsr1single = tffsr1.toSingleLabelTransitions();
Utils.showDot(tffsr1single.toDot("single labels tffsr1"));
}
}
\ No newline at end of file
/*
* Created on 12-Aug-2004
*
* Copyright (C) 2004 Javier Baliosian
* All rights reserved.
* */
package uy.edu.fing.mina.fsa.test.operations;
import uy.edu.fing.mina.fsa.tf.SimpleTf;
import uy.edu.fing.mina.fsa.tf.TfI;
import uy.edu.fing.mina.fsa.tf.TfString;
import uy.edu.fing.mina.fsa.tffsr.Tffsr;
import uy.edu.fing.mina.fsa.tffst.State;
import uy.edu.fing.mina.fsa.tffst.Tffst;
import uy.edu.fing.mina.fsa.tffst.Transition;
import uy.edu.fing.mina.fsa.utils.Utils;
/**
* @author Javier Baliosian &lt; <a
* href="mailto:jbaliosian@tsc.upc.es">jbaliosian@tsc.upc.es </a>&gt;
*/
public class TffstComplement0 {
/**
* uy.edu.fing.mina.omega.tffst.test 8. it shows determinization of a union
*
* @param args
*/
public static void main(String[] args) {
Tffst.setMinimizeAlways(false);
Tffst tffst1 = new Tffst();
State s0 = new State();
tffst1.setInitialState(s0);
State s1 = new State();
s1.setAccept(true);
SimpleTf tfa = new SimpleTf("A");
Transition trans1 = new Transition(tfa, tfa, s1,1);
s0.addOutTran(trans1);
Tffst tffst1comp = tffst1.complement();
Utils.showDot(tffst1.toDot("tffst1"));
Utils.showDot(tffst1comp.toDot("tffst1comp"));
}
}
\ No newline at end of file
/*
* Created on 12-Aug-2004
*
* Copyright (C) 2004 Javier Baliosian
* All rights reserved.
* */
package uy.edu.fing.mina.fsa.test.operations;
import uy.edu.fing.mina.fsa.tf.SimpleTf;
import uy.edu.fing.mina.fsa.tf.TfI;
import uy.edu.fing.mina.fsa.tf.TfString;
import uy.edu.fing.mina.fsa.tffsr.State;
import uy.edu.fing.mina.fsa.tffsr.Tffsr;
import uy.edu.fing.mina.fsa.tffsr.Transition;
import uy.edu.fing.mina.fsa.utils.Utils;
/**
* @author Javier Baliosian &lt; <a
* href="mailto:jbaliosian@tsc.upc.es">jbaliosian@tsc.upc.es </a>&gt;
*/
public class TotalizeTffsr {
/**
* uy.edu.fing.mina.omega.tffst.test 8. it shows determinization of a union
*
* @param args
*/
public static void main(String[] args) {
Tffsr tffsr1 = new Tffsr();
State s0 = new State();
tffsr1.setInitialState(s0);
State s1 = new State();
State s2 = new State();
s2.setAccept(true);
SimpleTf tfd = new SimpleTf();
tfd.setName("D");
Transition trans1 = new Transition(new TfString(tfd), s1);
s0.addOutTran(trans1);
SimpleTf tfall = new SimpleTf();
tfall.setAcceptAll();
SimpleTf tfc = new SimpleTf();
tfc.setName("C");
TfI tfall_c = tfall.and(tfc.not());
Transition trans2 = new Transition(new TfString(tfall_c), s2);
s1.addOutTran(trans2);
SimpleTf tfk = new SimpleTf();
tfk.setName("K");
TfString sec = new TfString(tfc);
Transition trans3 = new Transition(sec, s2);
s1.addOutTran(trans3);
Utils.showDot(tffsr1.toDot("tffsr1"));
Tffsr tffsr1total = tffsr1.totalize();
Utils.showDot(tffsr1total.toDot("totalized tffsr1"));
}
}
\ No newline at end of file
/*
* Created on 12-Aug-2004
*
* Copyright (C) 2004 Javier Baliosian
* All rights reserved.
* */
package uy.edu.fing.mina.fsa.test.operations;
import uy.edu.fing.mina.fsa.tf.SimpleTf;
import uy.edu.fing.mina.fsa.tf.TfI;
import uy.edu.fing.mina.fsa.tf.TfString;
import uy.edu.fing.mina.fsa.tffst.State;
import uy.edu.fing.mina.fsa.tffst.Tffst;
import uy.edu.fing.mina.fsa.tffst.Transition;
import uy.edu.fing.mina.fsa.utils.Utils;
/**
* @author Javier Baliosian &lt; <a
* href="mailto:jbaliosian@tsc.upc.es">jbaliosian@tsc.upc.es </a>&gt;
*/
public class TotalizeTffst {
/**
* uy.edu.fing.mina.omega.tffst.test 8. it shows determinization of a union
*
* @param args
*/
public static void main(String[] args) {
Tffst tffst1 = new Tffst();
State s0 = new State();
tffst1.setInitialState(s0);
State s1 = new State();
s1.setAccept(true);
SimpleTf tfd = new SimpleTf();
tfd.setName("D");
Transition trans1 = new Transition(new TfString(tfd),new TfString(tfd), s1);
s0.addOutTran(trans1);
Utils.showDot(tffst1.toDot("tffst1"));
Tffst tffst1total = tffst1.totalize();
Utils.showDot(tffst1total.toDot("totalized tffst1"));
}
}
\ No newline at end of file
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