Commit 4002bb12 authored by Javier Baliosian's avatar Javier Baliosian
Browse files


Signed-off-by: Javier Baliosian's avatarbaliosian <javierba@fing.edu.uy>
parent 30e3f1fd
package uy.edu.fing.mina.fsa.logics;
import uy.edu.fing.mina.fsa.tf.TfI;
import uy.edu.fing.mina.fsa.tf.LabelI;
public class Implication {
TfI all;
TfI are;
LabelI all;
LabelI are;
public Implication(TfI all, TfI are) {
public Implication(LabelI all, LabelI are) {
super();
this.all = all;
this.are = are;
......
......@@ -23,7 +23,7 @@ import uy.edu.fing.mina.fsa.logics.quineMcCluskey.TfTerm;
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.tf.LabelI;
import uy.edu.fing.mina.fsa.tf.TfPair;
/**
......@@ -32,9 +32,9 @@ import uy.edu.fing.mina.fsa.tf.TfPair;
*/
public class Utils {
public static TfI disjunctiveFormByMua(TfI tf) {
public static LabelI disjunctiveFormByMua(LabelI tf) {
TfI dnftf = null;
LabelI dnftf = null;
if (tf instanceof CompositeTf)
dnftf = ((CompositeTf) tf).toDNF();
......@@ -57,10 +57,10 @@ public class Utils {
/*
* @see uy.edu.fing.mina.omega.tffst.utils.tf.TfI#simplify()
*/
public static TfI simplify(TfI tf) {
public static LabelI simplify(LabelI tf) {
// TfI simplifiedTf = disjunctiveForm(tf);
TfI simplifiedTf = disjunctiveFormByMua(tf);
LabelI simplifiedTf = disjunctiveFormByMua(tf);
List<Term> termList = toTermList(simplifiedTf);
......@@ -237,9 +237,9 @@ public class Utils {
return outTermList;
}
private static TfI termsListToTf(List<Term> termList) {
private static LabelI termsListToTf(List<Term> termList) {
TfI out = null;
LabelI out = null;
for (Iterator<Term> iterator = termList.iterator(); iterator.hasNext();) {
Term term = (Term) iterator.next();
......@@ -251,9 +251,9 @@ public class Utils {
return out;
}
private static TfI termToTf(Term term) {
private static LabelI termToTf(Term term) {
TfI out = null;
LabelI out = null;
for (int i = 0; i < term.varVals.length; i++) {
TfTerm tfterm = term.varVals[i];
......@@ -282,7 +282,7 @@ public class Utils {
* has to be in DNF
* @return
*/
public static List<Term> toTermList(TfI tf) {
public static List<Term> toTermList(LabelI tf) {
List<Term> termList = new ArrayList<Term>();
......
package uy.edu.fing.mina.fsa.logics.quineMcCluskey;
import uy.edu.fing.mina.fsa.tf.SimpleTf;
import uy.edu.fing.mina.fsa.tf.TfI;
import uy.edu.fing.mina.fsa.tf.LabelI;
public class TfTerm {
public TfTerm(TfI t, byte i) {
public TfTerm(LabelI t, byte i) {
b = i;
this.tf = t;
}
public byte b;
public TfI tf;
public LabelI tf;
public static final TfTerm DontCare = new TfTerm(SimpleTf.AcceptsNone(), (byte) 2);
......
......@@ -19,17 +19,17 @@ public class CompositeTf extends Tf {
*/
private static final long serialVersionUID = 1L;
public TfI left;
public LabelI left;
public String op;
public TfI right;
public LabelI right;
public CompositeTf() {
super();
}
public CompositeTf(String op, TfI leftTf, TfI rightTf) {
public CompositeTf(String op, LabelI leftTf, LabelI rightTf) {
super();
this.op = op;
......@@ -48,8 +48,8 @@ public class CompositeTf extends Tf {
* @param tf
* @return
*/
public static ArrayList<TfI> ctfToArrayList(TfI tf) {
ArrayList<TfI> listOfTfs = new ArrayList<TfI>();
public static ArrayList<LabelI> ctfToArrayList(LabelI tf) {
ArrayList<LabelI> listOfTfs = new ArrayList<LabelI>();
if (tf instanceof SimpleTf) {
listOfTfs.add(tf);
......@@ -70,11 +70,11 @@ public class CompositeTf extends Tf {
if (left instanceof SimpleTf)
clon.left = left;
else
clon.left = (TfI) left.clone();
clon.left = (LabelI) left.clone();
if (right instanceof SimpleTf)
clon.right = right;
else
clon.right = (TfI) right.clone();
clon.right = (LabelI) right.clone();
clon.op = op;
......@@ -101,7 +101,7 @@ public class CompositeTf extends Tf {
/**
* @return Returns the leftTf.
*/
public TfI getLeftTf() {
public LabelI getLeftTf() {
return left;
}
......@@ -115,7 +115,7 @@ public class CompositeTf extends Tf {
/**
* @return Returns the rightTf.
*/
public TfI getRightTf() {
public LabelI getRightTf() {
return right;
}
......@@ -123,7 +123,7 @@ public class CompositeTf extends Tf {
* @param leftTf
* The leftTf to set.
*/
public void setLeftTf(TfI leftTf) {
public void setLeftTf(LabelI leftTf) {
this.left = leftTf;
}
......@@ -139,7 +139,7 @@ public class CompositeTf extends Tf {
* @param rightTf
* The rightTf to set.
*/
public void setRightTf(TfI rightTf) {
public void setRightTf(LabelI rightTf) {
this.right = rightTf;
}
......@@ -202,10 +202,10 @@ public class CompositeTf extends Tf {
return false;
}
public boolean in(TfI tf) {
public boolean in(LabelI tf) {
tf = Utils.simplify(tf);
TfI simplythis = Utils.simplify(this);
LabelI simplythis = Utils.simplify(this);
if (simplythis.equals(tf)) return true;
else if (tf.acceptsAll()) return true;
else if (simplythis.and(tf).equals(tf)) return true;
......@@ -223,20 +223,20 @@ public int hashCode() {
* @param operator
* @return
*/
public static TfI listToCTF(String operator, ArrayList<TfI> rightArray) {
public static LabelI listToCTF(String operator, ArrayList<LabelI> rightArray) {
ArrayList<TfI> auxArrayList = new ArrayList<TfI>();
ArrayList<LabelI> auxArrayList = new ArrayList<LabelI>();
for (Iterator<TfI> iter = rightArray.iterator(); iter.hasNext();) {
TfI o = iter.next();
for (Iterator<LabelI> iter = rightArray.iterator(); iter.hasNext();) {
LabelI o = iter.next();
if (o != null)
auxArrayList.add(o);
}
rightArray = auxArrayList;
Iterator<TfI> raIter = rightArray.iterator();
TfI partitionR1 = null;
Iterator<LabelI> raIter = rightArray.iterator();
LabelI partitionR1 = null;
Object o1 = null;
Object o2 = null;
......@@ -250,21 +250,21 @@ public int hashCode() {
if (o1 == null)
return null;
else if (o2 == null)
return (TfI) o1;
return (LabelI) o1;
else {
if (operator.equals(Operator.AND))
partitionR1 = ((TfI)o1).and((TfI) o2);
partitionR1 = ((LabelI)o1).and((LabelI) o2);
else if (operator.equals(Operator.OR))
partitionR1 = ((TfI)o1).or((TfI) o2);
partitionR1 = ((LabelI)o1).or((LabelI) o2);
while (raIter.hasNext()) {
Object o = raIter.next();
if (o != null) {
TfI partitionR2 = null;
LabelI partitionR2 = null;
if (operator.equals(Operator.AND))
partitionR1 = partitionR1.and((TfI) o);
partitionR1 = partitionR1.and((LabelI) o);
else if (operator.equals(Operator.OR))
partitionR2 = partitionR1.or((TfI) o);
partitionR2 = partitionR1.or((LabelI) o);
if (partitionR2 instanceof CompositeTf) {
CompositeTf ctfPartitionR2 = (CompositeTf) partitionR2;
......
......@@ -18,7 +18,7 @@ import java.util.Set;
* href="mailto:jbaliosian@tsc.upc.es">jbaliosian@tsc.upc.es </a>&gt;
*/
public interface TfI extends java.io.Serializable {
public interface LabelI extends java.io.Serializable {
public static final float MAX_TF = 1;
public static final float MIN_TF = 0;
......@@ -27,15 +27,15 @@ public interface TfI extends java.io.Serializable {
public boolean acceptsNone();
public TfI not();
public LabelI not();
public TfI or(TfI tf);
public LabelI or(LabelI tf);
public TfI and(TfI tf);
public LabelI and(LabelI tf);
public TfI orSimple(TfI tf);
public LabelI orSimple(LabelI tf);
public TfI andSimple(TfI tf);
public LabelI andSimple(LabelI tf);
public Object clone() throws CloneNotSupportedException;
......@@ -47,7 +47,7 @@ public interface TfI extends java.io.Serializable {
public String getName();
public boolean in(TfI tf);
public boolean in(LabelI tf);
public boolean isEpsilon();
......@@ -61,9 +61,9 @@ public interface TfI extends java.io.Serializable {
public int getId();
public TfI refersTo();
public LabelI refersTo();
public void setRefersTo(TfI refersTo);
public void setRefersTo(LabelI refersTo);
public boolean satisfiable();
......@@ -71,8 +71,8 @@ public interface TfI extends java.io.Serializable {
public int hashCode();
public Set<TfI> getWeight();
public Set<LabelI> getWeight();
public void addWeight(TfI tf);
public void addWeight(LabelI tf);
}
\ No newline at end of file
......@@ -10,10 +10,10 @@ import uy.edu.fing.mina.fsa.utils.CombinationGenerator;
public class Partition {
public List<TfI> left = null;
public List<TfI> right = null;
public List<LabelI> left = null;
public List<LabelI> right = null;
public Partition(List<TfI> left, List<TfI> right) {
public Partition(List<LabelI> left, List<LabelI> right) {
super();
this.left = left;
this.right = right;
......@@ -28,23 +28,23 @@ public class Partition {
* @param relation
* @return
*/
public static TfI toTfrelation3(Partition relation) {
public static LabelI toTfrelation3(Partition relation) {
TfI tfrelation = null;
LabelI tfrelation = null;
if (relation.left != null) {
if (relation.left.size() == 1)
System.out.println(relation.left);
for (Iterator<TfI> iter = relation.left.iterator(); iter.hasNext();) {
TfI element = iter.next();
for (Iterator<LabelI> iter = relation.left.iterator(); iter.hasNext();) {
LabelI element = iter.next();
if (tfrelation == null) tfrelation = element;
else
tfrelation = tfrelation.andSimple(element);
}
}
if (relation.right != null) {
for (Iterator<TfI> iter2 = relation.right.iterator(); iter2.hasNext();) {
TfI element = iter2.next();
for (Iterator<LabelI> iter2 = relation.right.iterator(); iter2.hasNext();) {
LabelI element = iter2.next();
tfrelation = tfrelation.andSimple(element.not());
}
}
......@@ -60,7 +60,7 @@ public class Partition {
for (Iterator<TfPair> iter = partitions.iterator(); iter.hasNext();) {
TfPair partition = (TfPair) iter.next();
TfI tfpartition = null;
LabelI tfpartition = null;
if (partition.getTfIn() != null && partition.getTfOut() != null)
tfpartition = partition.getTfIn().and(partition.getTfOut().not());
else if (partition.getTfIn() != null )
......@@ -77,7 +77,7 @@ public class Partition {
for (Iterator<TfPair> iter2 = partitions.iterator(); iter2.hasNext();) {
TfPair partition2 = (TfPair) iter2.next();
TfI tfpartition2 = null;
LabelI tfpartition2 = null;
if (partition2.getTfIn() != null && partition2.getTfOut() != null)
tfpartition2 = partition2.getTfIn().and(partition2.getTfOut().not());
else if (partition.getTfIn() != null )
......@@ -108,7 +108,7 @@ public class Partition {
* @return a set of TfPairs
*
*/
public static Set<TfPair> getPartitions2(String op1, String op2, Set<TfI> tfs) {
public static Set<TfPair> getPartitions2(String op1, String op2, Set<LabelI> tfs) {
CombinationGenerator cg;
Set<TfPair> partitions = new HashSet<TfPair>();
......@@ -117,21 +117,21 @@ public class Partition {
int[] indices;
cg = new CombinationGenerator(tfs.size(), i);
while (cg.hasMore()) {
ArrayList<TfI> rightArray = new ArrayList<TfI>();
ArrayList<LabelI> rightArray = new ArrayList<LabelI>();
rightArray.addAll(tfs);
indices = cg.getNext();
// building left part of partition with ANDs
ArrayList<TfI> leftArray = new ArrayList<TfI>();
ArrayList<LabelI> leftArray = new ArrayList<LabelI>();
for (int j = 0; j < indices.length; j++) {
leftArray.add(rightArray.get(indices[j]));
rightArray.set(indices[j], null);
}
TfI partitionL = CompositeTf.listToCTF(op1, leftArray);
LabelI partitionL = CompositeTf.listToCTF(op1, leftArray);
if (!rightArray.isEmpty()) {
TfI partitionR = CompositeTf.listToCTF(op2, rightArray);
LabelI partitionR = CompositeTf.listToCTF(op2, rightArray);
partitions.add(new TfPair(partitionL, partitionR));
} else {
partitions.add(new TfPair(partitionL, null));
......@@ -154,7 +154,7 @@ public class Partition {
* @return a set of TfPairs with a TfString in each side.
*
*/
public static Set<Partition> getPartitions3(Set<TfI> tfs) {
public static Set<Partition> getPartitions3(Set<LabelI> tfs) {
CombinationGenerator cg;
......@@ -164,11 +164,11 @@ public class Partition {
int[] indices;
cg = new CombinationGenerator(tfs.size(), i);
while (cg.hasMore()) {
ArrayList<TfI> rightArray = new ArrayList<TfI>();
ArrayList<LabelI> rightArray = new ArrayList<LabelI>();
rightArray.addAll(tfs);
indices = cg.getNext();
ArrayList<TfI> leftArray = new ArrayList<TfI>();
ArrayList<LabelI> leftArray = new ArrayList<LabelI>();
for (int j = 0; j < indices.length; j++) {
leftArray.add(rightArray.get(indices[j]));
rightArray.set(indices[j], null);
......
......@@ -110,7 +110,7 @@ public class SimpleTf extends Tf {
}
/**
* @see uy.edu.fing.mina.omega.tffst.utils.tf.TfI#size()
* @see uy.edu.fing.mina.LabelI.tffst.utils.tf.TfI#size()
*/
public int size() {
return 1;
......@@ -127,7 +127,7 @@ public class SimpleTf extends Tf {
return out;
}
public boolean in(TfI tf) {
public boolean in(LabelI tf) {
//TODO faltan casos
......
......@@ -22,7 +22,7 @@ import uy.edu.fing.mina.fsa.logics.Utils;
* href="mailto:jbaliosian@tsc.upc.es">jbaliosian@tsc.upc.es </a>&gt;
*/
public abstract class Tf implements TfI, Cloneable, Comparable {
public abstract class Tf implements LabelI, Cloneable, Comparable {
/**
*
......@@ -33,14 +33,14 @@ public abstract class Tf implements TfI, Cloneable, Comparable {
private int id; //TODO check with lupa team if this can be removed
private TfI refersTo;
private LabelI refersTo;
private int identityType;
private Set<TfI> weightTf;
private Set<LabelI> weightTf;
/** A map with all the TFs which have a label different than ""*/
static public Map<String,TfI> createdTFs = new HashMap<String, TfI>();
static public Map<String,LabelI> createdTFs = new HashMap<String, LabelI>();
public Tf() {
this(false, "");
......@@ -61,7 +61,7 @@ public abstract class Tf implements TfI, Cloneable, Comparable {
this.not = not;
this.refersTo = null;
this.identityType = 0;
this.weightTf = new HashSet<TfI>();
this.weightTf = new HashSet<LabelI>();
}
abstract public boolean acceptsAll();
......@@ -76,8 +76,8 @@ public abstract class Tf implements TfI, Cloneable, Comparable {
* @return
*
*/
public TfI or(TfI tf) {
TfI outTf;
public LabelI or(LabelI tf) {
LabelI outTf;
// if (this.acceptsAll() || tf.acceptsAll()) {
// SimpleTf stf = new SimpleTf();
......@@ -110,8 +110,8 @@ public abstract class Tf implements TfI, Cloneable, Comparable {
* @return a simplified version of the formula.
*/
public TfI orSimple(TfI tf) {
TfI outTf;
public LabelI orSimple(LabelI tf) {
LabelI outTf;
// --
if (this.acceptsAll() || tf.acceptsAll()) {
......@@ -148,8 +148,8 @@ public abstract class Tf implements TfI, Cloneable, Comparable {
*
*/
public TfI and(TfI tf) {
TfI outTf;
public LabelI and(LabelI tf) {
LabelI outTf;
if (this.acceptsNone() || tf.acceptsNone()) {
SimpleTf stf = new SimpleTf();
......@@ -180,8 +180,8 @@ public abstract class Tf implements TfI, Cloneable, Comparable {
* @return a simplified version of the formula.
*/
public TfI andSimple(TfI tf) {
TfI outTf;
public LabelI andSimple(LabelI tf) {
LabelI outTf;
if (this.acceptsNone() || tf.acceptsNone()) {
SimpleTf stf = new SimpleTf();
......@@ -238,7 +238,7 @@ public abstract class Tf implements TfI, Cloneable, Comparable {
return not;
}
public TfI not() {
public LabelI not() {
if (isEpsilon())
return SimpleTf.AcceptsAll();
......@@ -249,8 +249,8 @@ public abstract class Tf implements TfI, Cloneable, Comparable {
else
try {
TfI r;
r = (TfI) clone();
LabelI r;
r = (LabelI) clone();
r.setNot(!isNot());
return r;
} catch (CloneNotSupportedException e) {
......@@ -267,11 +267,11 @@ public int getId() {
return id;
}
public TfI refersTo() {
public LabelI refersTo() {
return refersTo;
}
public void setRefersTo(TfI refersTo) {
public void setRefersTo(LabelI refersTo) {
this.refersTo = refersTo;
}
......@@ -336,14 +336,14 @@ public int hashCode() {
/**
* @return the weight
*/
public Set<TfI> getWeight() {
public Set<LabelI> getWeight() {
return weightTf;
}
/**
* @param weight the weight to set
*/
public void addWeight(TfI weight) {
public void addWeight(LabelI weight) {
this.weightTf.add(weight);
}
......
......@@ -25,9 +25,9 @@ public class TfPair extends SimpleTf {
*/
private static final long serialVersionUID = 1L;
public TfI tfIn;
public LabelI tfIn;
public TfI tfOut;
public LabelI tfOut;
/* Constructors *********************************************************** */
......@@ -36,7 +36,7 @@ public class TfPair extends SimpleTf {
this(SimpleTf.Epsilon(), SimpleTf.Epsilon());
}
public TfPair(TfI tfIn, TfI tfOut) {
public TfPair(LabelI tfIn, LabelI tfOut) {
this.tfIn = tfIn;
this.tfOut = tfOut;
}
......@@ -52,14 +52,14 @@ public class TfPair extends SimpleTf {
/**
* @return Returns the tfIn.
*/
public TfI getTfIn() {
public LabelI getTfIn() {
return tfIn;
}
/**
* @return Returns the tfOut.</