Commit 801e5361 authored by Javier Baliosian's avatar Javier Baliosian
Browse files

merge con el master viejo

parents 219b8012 e951b924
......@@ -67,6 +67,18 @@ local function dump_window()
return s
end
local function dump_window()
local s="=> "
for _,e in ipairs(window) do
if e.event.message_type=="trap" then
s=s .. tostring(e.event.watcher_id) ..","
else
s=s .. "#,"
end
end
return s
end
--advances the machine a single step.
--returns nil if arrives at the end the window, or the event is not recognized
--otherwise, returns the resulting list from the action
......@@ -99,8 +111,13 @@ local function fst_step()
i_event=i_event+1
current_state = transition.new
<<<<<<< HEAD
print ("NEW STATE:", current_state, "#TRANS:", #fsm[current_state], "#RETS:", #ret_call, "ACCEPT:", is_accept[current_state], "FINAL:", #fsm[current_state]==0)
return ret_call, is_accept[current_state], #fsm[current_state]==0
=======
return ret_call or {}, is_accept(current_state), #fsm[current_state]==0
>>>>>>> master
end
function step()
......@@ -109,29 +126,48 @@ function step()
local ret, accept, final = {}, false, false
repeat
<<<<<<< HEAD
local ret_step
ret_step, accept, final = fst_step()
if ret_step then
for _, r in ipairs(ret_step) do ret[#ret+1]=r end --queue generated actions
end
until accept or i_event>#window
=======
local ret_step, accept, final = fst_step()
if ret_step then
for _, r in ipairs(ret_step) do ret[#ret+1]=r end --queue generated actions
end
until accept or i_event==#window
>>>>>>> master
assert(not (final and not accept))
if accept then
--purge consumed events from window
<<<<<<< HEAD
print("Purge consumed events", #window)
=======
>>>>>>> master
local i=1
local e = window[i_event]
repeat
if happening_events[window[i]] then
i=i+1
else
<<<<<<< HEAD
table.remove(window, i)
i_event=i_event-1
end
until window[i]==e
if not happening_events[window[i]] then table.remove(window, i) end
print("Purge consumed events", #window)
=======
table.remove[window, i]
i_event=i_event-1
end
until window[i]==e
if not happening_events[window[i]] then table.remove[window, i] end
>>>>>>> master
end
if #ret>0 then
......@@ -144,7 +180,10 @@ function reset()
current_state=init_state
i_event=1
happening_events={}
<<<<<<< HEAD
print ("FSM: RESET")
=======
>>>>>>> master
end
print ("FSM loaded.")
......
/*
* Created on 12-Aug-2004
*
* Copyright (C) 2004 Javier Baliosian
* All rights reserved.
* */
package uy.edu.fing.mina.fsa.test;
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;
import uy.edu.fing.mina.lupa.LupaExporter;
import uy.edu.fing.mina.lupa.exceptions.UnsupportedTFFSTException;
import uy.edu.fing.mina.lupa.tf.ActionTf;
import uy.edu.fing.mina.lupa.tf.EventTf;
/**
* @author Javier Baliosian &lt; <a
* href="mailto:jbaliosian@tsc.upc.es">jbaliosian@tsc.upc.es </a>&gt;
*/
public class TestLupa {
/**
* composition test 1
*
* @param args
*/
public static void main(String[] args) {
//
// Tffst.setMinimizeAlways(false);
//
//
//// tffst1 :
//// !D/!D
//// ┌───────────┐
//// ▼ │
//// ┌───────────────┐ D/D ╔═══╗
////initial ──▶ │ 0 │ ─────▶ ║ 1 ║
//// └───────────────┘ ╚═══╝
//
//
// Tffst tffst1 = new Tffst();
//
// State s0 = new State();
// tffst1.setInitialState(s0);
// State s1 = new State();
// s1.setAccept(true);
//
// EventTf d = new EventTf();
// d.setSLabel("eventD");
//
// ActionTf cAction2 = new ActionTf();
// cAction2.setSLabel("actionC");
//
// ActionTf dAction = new ActionTf();
// dAction.setSLabel("actionD");
//
// s0.addTransition(new Transition(d, cAction2, s1));
// s0.addTransition(new Transition(d.not(), cAction2.not(), s0));
//
// Utils.showDot(tffst1.toDot("tffst1"));
//
//
//// tffst2
////
//// !C/!C
//// ┌───────────┐
//// ▼ │
//// ┌───────────────┐ C/C ╔═══╗
//// initial ──▶ │ 20 │ ────▶ ║21 ║
//// └───────────────┘ ╚═══╝
//
// Tffst tffst2 = new Tffst();
//
// State s20 = new State();
// tffst2.setInitialState(s20);
// State s21 = new State();
// s21.setAccept(true);
//
// EventTf cEvent = new EventTf();
// cEvent.setSLabel("eventC");
//
// ActionTf cAction = new ActionTf();
// cAction.setSLabel("actionC");
//
// ActionTf eAction = new ActionTf();
// eAction.setSLabel("actionE");
//
// s20.addTransition(new Transition(cEvent.not(), cAction.not(), s20));
// s20.addTransition(new Transition(cEvent,eAction , s21));
//
// Utils.showDot(tffst2.toDot("tffst2"));
//
// Tffst tffstComposition = tffst1.composition(tffst2);
//
// try {
// LupaExporter.generateLupaFiles(tffstComposition, "fsm_template.lua", "out_test_pdp_aux");
// } catch (UnsupportedTFFSTException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
//
// Utils.showDot(tffstComposition.toDot("tffst1 o tffst2"));
//
//
}
}
\ No newline at end of file
......@@ -37,6 +37,8 @@ public abstract class Tf implements TfI, Cloneable, Comparable {
private Set<TfI> weightTf;
public Tf() {
this(false, "");
}
......@@ -99,10 +101,10 @@ public abstract class Tf implements TfI, Cloneable, Comparable {
/**
* The OR operator with an automatic Quinn-McCluskey simplification.
*
* The OR operator with an automatic Quinn-McCluskey simplification.
*
* @param tf
* @return a simplified version of the formula.
* @return a simplified version of the formula.
*/
public TfI orSimple(TfI tf) {
......@@ -110,25 +112,29 @@ public abstract class Tf implements TfI, Cloneable, Comparable {
// --
if (this.acceptsAll() || tf.acceptsAll()) {
SimpleTf stf = new SimpleTf();
stf.setAcceptAll();
outTf = stf;
} else if (this.acceptsNone()) {
outTf = tf;
} else if (tf.acceptsNone()) {
outTf = this;
} else if (this.equals(tf)) {
outTf = this;
} else if (this.equals(tf.not())) {
SimpleTf stf = new SimpleTf();
stf.setAcceptAll();
outTf = stf;
}else if (this instanceof SimpleTf && tf instanceof SimpleTf ) {
outTf = new CompositeTf(Operator.OR, this, tf);
} else {
outTf = new CompositeTf(Operator.OR, this, tf);
outTf = Utils.simplify(outTf);
}
SimpleTf stf = new SimpleTf();
stf.setAcceptAll();
outTf = stf;
} else if (this.isEpsilon()) {
outTf = tf;
} else if (tf.isEpsilon()) {
outTf = this;
} else if (this.acceptsNone()) {
outTf = tf;
} else if (tf.acceptsNone()) {
outTf = this;
} else if (this.equals(tf)) {
outTf = this;
} else if (this.equals(tf.not())) {
SimpleTf stf = new SimpleTf();
stf.setAcceptAll();
outTf = stf;
} else if (this instanceof SimpleTf && tf instanceof SimpleTf) {
outTf = new CompositeTf(Operator.OR, this, tf);
} else {
outTf = new CompositeTf(Operator.OR, this, tf);
outTf = Utils.simplify(outTf);
}
// --
return outTf;
}
......
......@@ -1332,6 +1332,7 @@ public class Tffst implements Serializable {
for (Transition t : eop.state.getTransitions()) {
if (tf.equals(t.labelIn.isEpsilon() ? SimpleTf.Epsilon(): t.labelIn.get(0))) {
TfString newSE = new TfString();
for (TfI tfpairp : eop.getArrivingTFs()) {
if (!tfpairp.isEpsilon() && !t.labelIn.isEpsilon()) tfpairp.addWeight(t.labelIn.get(0));
......@@ -1347,6 +1348,7 @@ public class Tffst implements Serializable {
}
retPair = new ElementOfP(t.getTo(), newSE);
unionOfTransPelements.add(retPair);
}
}
......
......@@ -272,7 +272,9 @@ public class LupaExporter {
out_notifs.append(" ").append(init).append(",\n");
}
}
Iterator<String> inits_subs = e.getInitSubsStrings().iterator();
while (inits_subs.hasNext()) {
String init = inits_subs.next();
if (!init_subs_generated.contains(init)) {
......@@ -422,7 +424,9 @@ public class LupaExporter {
out = out.concat("\tif left < right then return left else return right end\n");
} else if (comp.op == Operator.OR) {
out = out.concat("\tif left > right then return left else return right end\n");
}
out = out.concat("end\n");
}
else if (function.isNot()) {
......@@ -446,6 +450,7 @@ public class LupaExporter {
return out;
}
/**
* Creates a String with actions functions that are CompositeTf or Nots.
*
......@@ -501,6 +506,7 @@ public class LupaExporter {
return out;
}
// private static String actionsToLupa(Tffst tffst) {
......
......@@ -35,6 +35,7 @@ public class EventTf extends SimpleTf {
}
public Set<String> getInitSubsStrings() {
return init_subs_strings;
}
......
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