Skip to content

Commit

Permalink
Corrections to Troolean operators
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvainhalle committed Jun 12, 2024
1 parent b532220 commit 2a72fd7
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 110 deletions.
12 changes: 12 additions & 0 deletions Ltl/src/ca/uqac/lif/cep/ltl/BooleanFirstOrderQuantifier.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ca.uqac.lif.cep.ltl;

import ca.uqac.lif.cep.Processor;
import ca.uqac.lif.cep.functions.Function;

public abstract class BooleanFirstOrderQuantifier extends FirstOrderQuantifier
{
public BooleanFirstOrderQuantifier(String var_name, Function dom_function, Processor expression)
{
super(var_name, dom_function, expression, true);
}
}
2 changes: 1 addition & 1 deletion Ltl/src/ca/uqac/lif/cep/ltl/Every.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class Every extends FirstOrderQuantifier
{
public Every(String var_name, Function dom_function, Processor expression)
{
super(var_name, dom_function, expression);
super(var_name, dom_function, expression, false);
}

protected Every(FirstOrderSlice fos)
Expand Down
2 changes: 1 addition & 1 deletion Ltl/src/ca/uqac/lif/cep/ltl/Exists.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class Exists extends FirstOrderQuantifier
{
public Exists(String var_name, Function dom_function, Processor expression)
{
super(var_name, dom_function, expression);
super(var_name, dom_function, expression, true);
}

protected Exists(FirstOrderSlice fos)
Expand Down
4 changes: 2 additions & 2 deletions Ltl/src/ca/uqac/lif/cep/ltl/FirstOrderQuantifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public abstract class FirstOrderQuantifier extends SynchronousProcessor

protected SinkLast m_sink;

public FirstOrderQuantifier(String var_name, Function dom_function, Processor expression)
public FirstOrderQuantifier(String var_name, Function dom_function, Processor expression, boolean is_boolean)
{
super(1, 1);
m_slicer = new FirstOrderSlice(var_name, dom_function, expression);
m_slicer = new FirstOrderSlice(var_name, dom_function, expression, is_boolean);
m_slicerPushable = m_slicer.getPushableInput();
m_sink = new SinkLast();
Connector.connect(m_slicer, m_sink);
Expand Down
215 changes: 111 additions & 104 deletions Ltl/src/ca/uqac/lif/cep/ltl/FirstOrderSlice.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
BeepBeep, an event stream processor
Copyright (C) 2008-2018 Sylvain Hallé
Copyright (C) 2008-2024 Sylvain Hallé
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
Expand Down Expand Up @@ -32,107 +32,114 @@

public class FirstOrderSlice extends SynchronousProcessor
{
protected String m_varName;

protected Function m_function;

protected Processor m_expression;

protected List<Processor> m_slices;

protected List<Pushable> m_pushables;

protected List<SinkLast> m_sinks;

public FirstOrderSlice(String var_name, Function dom_function, Processor expression)
{
super(1, 1);
m_varName = var_name;
m_function = dom_function;
m_expression = expression;
m_slices = new ArrayList<Processor>();
m_pushables = new ArrayList<Pushable>();
m_sinks = new ArrayList<SinkLast>();
}

@Override
public FirstOrderSlice duplicate(boolean with_state)
{
FirstOrderSlice fos = new FirstOrderSlice(m_varName, m_function, m_expression);
fos.setContext(getContext());
if (with_state)
{
throw new UnsupportedOperationException("Duplication with state not supported yet on this processor");
}
return fos;
}

@Override
public void setContext(String key, Object value)
{
super.setContext(key, value);
for (Processor p : m_slices)
{
p.setContext(key, value);
}
}

@Override
public void setContext(Context c)
{
super.setContext(c);
for (Processor p : m_slices)
{
p.setContext(c);
}
}

@Override
public void reset()
{
super.reset();
m_slices.clear();
m_function.reset();
}

@Override
protected boolean compute(Object[] inputs, Queue<Object[]> outputs)
{
// Evaluate domain function
Object[] values = new Object[1];
m_function.evaluate(inputs, values);
// Create new slice and set context
if (values[0] instanceof Collection<?>)
{
for (Object val : (Collection<?>) values[0])
{
Processor new_p = m_expression.duplicate();
new_p.setContext(m_context);
new_p.setContext(m_varName, val);
// Connect to sink, add to lists
m_slices.add(new_p);
m_pushables.add(new_p.getPushableInput());
SinkLast sink = new SinkLast();
Connector.connect(new_p, sink);
m_sinks.add(sink);
}
}
// Push inputs to all slices
for (Pushable p : m_pushables)
{
p.push(inputs[0]);
}
// Collect output into a list
List<Object> out_vals = new ArrayList<Object>(m_pushables.size());
for (SinkLast sl : m_sinks)
{
Object[] oa = sl.getLast();
if (oa != null)
{
out_vals.add(oa[0]);
}
}
outputs.add(new Object[] {out_vals});
return true;
}
protected boolean m_boolean;

protected String m_varName;

protected Function m_function;

protected Processor m_expression;

protected List<Processor> m_slices;

protected List<Pushable> m_pushables;

protected List<SinkLast> m_sinks;

public FirstOrderSlice(String var_name, Function dom_function, Processor expression, boolean is_boolean)
{
super(1, 1);
m_boolean = is_boolean;
m_varName = var_name;
m_function = dom_function;
m_expression = expression;
m_slices = new ArrayList<Processor>();
m_pushables = new ArrayList<Pushable>();
m_sinks = new ArrayList<SinkLast>();
}

@Override
public FirstOrderSlice duplicate(boolean with_state)
{
FirstOrderSlice fos = new FirstOrderSlice(m_varName, m_function, m_expression, m_boolean);
fos.setContext(getContext());
if (with_state)
{
throw new UnsupportedOperationException("Duplication with state not supported yet on this processor");
}
return fos;
}

@Override
public void setContext(String key, Object value)
{
super.setContext(key, value);
for (Processor p : m_slices)
{
p.setContext(key, value);
}
}

@Override
public void setContext(Context c)
{
super.setContext(c);
for (Processor p : m_slices)
{
p.setContext(c);
}
}

@Override
public void reset()
{
super.reset();
m_slices.clear();
m_function.reset();
}

@Override
protected boolean compute(Object[] inputs, Queue<Object[]> outputs)
{
// Evaluate domain function
if (!m_boolean || m_inputCount == 0)
{
Object[] values = new Object[1];
m_function.evaluate(inputs, values);
// Create new slice and set context
if (values[0] instanceof Collection<?>)
{
for (Object val : (Collection<?>) values[0])
{
Processor new_p = m_expression.duplicate();
new_p.setContext(m_context);
new_p.setContext(m_varName, val);
// Connect to sink, add to lists
m_slices.add(new_p);
m_pushables.add(new_p.getPushableInput());
SinkLast sink = new SinkLast();
Connector.connect(new_p, sink);
m_sinks.add(sink);
}
}
m_inputCount++;
}
// Push inputs to all slices
for (Pushable p : m_pushables)
{
p.push(inputs[0]);
}
// Collect output into a list
List<Object> out_vals = new ArrayList<Object>(m_pushables.size());
for (SinkLast sl : m_sinks)
{
Object[] oa = sl.getLast();
if (oa != null)
{
out_vals.add(oa[0]);
}
}
outputs.add(new Object[] {out_vals});
return true;
}
}
2 changes: 1 addition & 1 deletion Ltl/src/ca/uqac/lif/cep/ltl/ForAll.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class ForAll extends FirstOrderQuantifier
{
public ForAll(String var_name, Function dom_function, Processor expression)
{
super(var_name, dom_function, expression);
super(var_name, dom_function, expression, true);
}

protected ForAll(FirstOrderSlice fos)
Expand Down
2 changes: 1 addition & 1 deletion Ltl/src/ca/uqac/lif/cep/ltl/Some.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class Some extends FirstOrderQuantifier
{
public Some(String var_name, Function dom_function, Processor expression)
{
super(var_name, dom_function, expression);
super(var_name, dom_function, expression, false);
}

protected Some(FirstOrderSlice fos)
Expand Down

0 comments on commit 2a72fd7

Please sign in to comment.