From 34187946bbbbcdfca6228e3ffe0cdd15d616f56a Mon Sep 17 00:00:00 2001 From: JulianKaeuser Date: Sat, 3 Jun 2017 18:34:14 +0200 Subject: [PATCH 01/17] Introduced Cluster, StateMachine, StateMachineWriter --- .../source/src/lowlevel/Cluster.java | 79 +++++++++++++++++++ .../source/src/lowlevel/StateMachine.java | 15 ++++ .../source/src/lowlevel/cluster_encoder.java | 44 ++++++++++- lowlevel_framework/source/src/main/Main.java | 29 ++++++- 4 files changed, 163 insertions(+), 4 deletions(-) create mode 100644 lowlevel_framework/source/src/lowlevel/Cluster.java create mode 100644 lowlevel_framework/source/src/lowlevel/StateMachine.java diff --git a/lowlevel_framework/source/src/lowlevel/Cluster.java b/lowlevel_framework/source/src/lowlevel/Cluster.java new file mode 100644 index 0000000..3e6c457 --- /dev/null +++ b/lowlevel_framework/source/src/lowlevel/Cluster.java @@ -0,0 +1,79 @@ +package lowlevel; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; + +/** + * Created by Julian Käuser on 03.06.2017. + */ +public class Cluster { + + private Set states; + + // should be either "binary" or "onehot" + private String internalEncoding; + + private int id; + + private int numInputs; + + public Cluster(){ + states = new HashSet(); + } + + public boolean addState(State state){ + return states.add(state); + } + + public State[] getStateArray(){ + return (State[]) states.toArray(); + } + + public boolean removeState(State state){ + return states.remove(state); + } + + public String getEncoding(){ + return internalEncoding; + } + + public void setEncoding(String enc){ + internalEncoding=enc; + } + + public void setID(int id){ + this.id = id; + } + + public int getID(){ + return id; + } + + public int getNumStates(){ + return states.size(); + } + + public int getInputs(){ + return numInputs; + } +} + + public String getEncodedCluster(){ + StringBuilder bld = new StringBuilder(); + + ClusterEncoder enc = new ClusterEncoder(); + HashMap map = null; + switch (getEncoding()) { + case "binary": + map = enc.encodeBinary(this.getStateArray(), this.getInputs()); + case "onehot": + map = enc.encodeOneHot(this.getStateArray(), this.getInputs()); + } + for (State s : map.keySet()) { + String str = ".code "+s.getName()+" "+map.get(s)+"\n"; + bld.append(str); + } + return bld.toString(); + } +} diff --git a/lowlevel_framework/source/src/lowlevel/StateMachine.java b/lowlevel_framework/source/src/lowlevel/StateMachine.java new file mode 100644 index 0000000..b4fcc8d --- /dev/null +++ b/lowlevel_framework/source/src/lowlevel/StateMachine.java @@ -0,0 +1,15 @@ +package lowlevel; + +import java.util.Set; + +/** + * Created by Julian Käuser on 03.06.2017. + */ +public class StateMachine { + + private Set clusters; + + public String getEncoding(){ + + } +} diff --git a/lowlevel_framework/source/src/lowlevel/cluster_encoder.java b/lowlevel_framework/source/src/lowlevel/cluster_encoder.java index 39243fd..76a26bf 100644 --- a/lowlevel_framework/source/src/lowlevel/cluster_encoder.java +++ b/lowlevel_framework/source/src/lowlevel/cluster_encoder.java @@ -1,14 +1,54 @@ package lowlevel; +import java.util.HashMap; + /** + * Julians Idee für diese Klasse: Nehme bis zu drei States, und setze ein One-Hot-Encoding ins Slice. + * -> Ergo 3 Flipflops * Created by theChaoS on 03.06.2017. */ -public class clusterEncoder { +public class ClusterEncoder { + final static int k=6; + final static int nFF=4; + + + public ClusterEncoder(){ + + } + + /** + * Takes the selected states for a cluster, namely in the array states, and packs them into a LUT-feasible + * format. Returns the encoding for this state cluster in one hot + * @param states the states in the cluster, each entry non-null + * @return A mapping of states to strings containing their one-hot value (as chars of {0,1}) + * if encoding is not possible (too many states), return null + */ + public HashMap encodeOneHot (State[] states, int nIn){ + HashMap result = new HashMap(); + + /* + precondition: states have yet been chosen regarding their clusterability + */ + + + + + } + + /** + * Takes the selected states for a cluster, namely in the array states, and packs them into a LUT-feasible + * format. Returns the encoding for this state cluster in binary encoding + * @param states the states in the cluster + * @return A mapping of states to strings containing their binary value (as chars of {0,1}) + */ + public HashMap encodeBinary(State[] states, int nIn){ + HashMap result = new HashMap(); + } } -public class oneHotEncoder extends clusterEncoder{ +public class oneHotEncoder extends ClusterEncoder{ } diff --git a/lowlevel_framework/source/src/main/Main.java b/lowlevel_framework/source/src/main/Main.java index 9665c16..85c3f4f 100644 --- a/lowlevel_framework/source/src/main/Main.java +++ b/lowlevel_framework/source/src/main/Main.java @@ -3,6 +3,9 @@ import io.Parser; import lowlevel.ParsedFile; +import java.io.File; +import java.io.FilenameFilter; + /** * Main class * @author Wolf & Gottschling @@ -19,8 +22,30 @@ public static void main(String[] args) { String relPath = "\\lowlevel_framework\\benchmarks\\kiss_files\\"; String userDir = System.getProperty("user.dir"); input_file_name = userDir+relPath+input_file_name; - - //ich füge mal nen KOmmentar ein + + File dir = new File(input_file_name); + ParsedFile[] inputFiles; + if (args[1]!=null && args[1]=="-all" && dir.isDirectory()){ + // args[0] is a directory, and all files of the directory shall be parsed + FilenameFilter filter = new FilenameFilter() { + @Override + public boolean accept(File dir, String name) { + if (name.endsWith(".kiss") || name.endsWith(".kiss2")){ + return true; + } + return false; + } + }; + inputFiles = new ParsedFile[dir.listFiles(filter).length]; + int ii=0; + for (File file : dir.listFiles(filter)) { + Parser p = new Parser(); + p.parseFile(file.getAbsolutePath()); + inputFiles[ii]=p.getParsedFile(); + ii++; + } + }// from this point on one could work on the whole folder... just for benchmarking reasons + Parser p = new Parser(); p.parseFile(input_file_name); From 837c26a244f664bbe65404a87572536cbb7d3713 Mon Sep 17 00:00:00 2001 From: JulianKaeuser Date: Sat, 3 Jun 2017 18:59:07 +0200 Subject: [PATCH 02/17] Further methods in StateMachineWriter, some adjustments --- lowlevel_framework/source/src/lowlevel/Cluster.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lowlevel_framework/source/src/lowlevel/Cluster.java b/lowlevel_framework/source/src/lowlevel/Cluster.java index 3e6c457..48eb6e6 100644 --- a/lowlevel_framework/source/src/lowlevel/Cluster.java +++ b/lowlevel_framework/source/src/lowlevel/Cluster.java @@ -14,7 +14,7 @@ public class Cluster { // should be either "binary" or "onehot" private String internalEncoding; - private int id; + private long id; private int numInputs; @@ -42,11 +42,11 @@ public void setEncoding(String enc){ internalEncoding=enc; } - public void setID(int id){ + public void setID(long id){ this.id = id; } - public int getID(){ + public long getID(){ return id; } @@ -57,7 +57,7 @@ public int getNumStates(){ public int getInputs(){ return numInputs; } -} + public String getEncodedCluster(){ StringBuilder bld = new StringBuilder(); From 7d4cd898d328cd2272d7f50cb99f74686fdb01a4 Mon Sep 17 00:00:00 2001 From: JulianKaeuser Date: Sun, 4 Jun 2017 08:02:28 +0200 Subject: [PATCH 03/17] Further methods in StateMachineWriter, some adjustments --- .../source/src/io/StateMachineWriter.java | 42 +++++++++++++++++++ .../source/src/lowlevel/StateMachine.java | 12 +++++- 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 lowlevel_framework/source/src/io/StateMachineWriter.java diff --git a/lowlevel_framework/source/src/io/StateMachineWriter.java b/lowlevel_framework/source/src/io/StateMachineWriter.java new file mode 100644 index 0000000..ea83be2 --- /dev/null +++ b/lowlevel_framework/source/src/io/StateMachineWriter.java @@ -0,0 +1,42 @@ +package io; + +import lowlevel.StateMachine; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; + +/** + * Created by Julian Käuser on 03.06.2017. + */ +public class StateMachineWriter { + + public static void writeFSM(StateMachine fsm, String destination){ + + if (fsm==null || destination==null){ + System.out.println("no fsm written - destination or fsm unknown"); + return; + } + StringBuilder bld = new StringBuilder(); + bld.append("# "+fsm.name +" encoded cluster-wise\n"); + bld.append(".i "+fsm.getNumInputs()+"\n"); + bld.append(".o "+fsm.getNumOutputs()+"\n"); + + // states and transitions + + bld.append(".end_kiss\n"); + bld.append(".latch_order "); // latch mapping + + + + try (FileWriter out = new FileWriter(destination)) { + BufferedWriter buf = new BufferedWriter(out); + buf.write(bld.toString()); + buf.flush(); + } + catch (IOException e){ + e.printStackTrace(); + } + } +} diff --git a/lowlevel_framework/source/src/lowlevel/StateMachine.java b/lowlevel_framework/source/src/lowlevel/StateMachine.java index b4fcc8d..2d0208c 100644 --- a/lowlevel_framework/source/src/lowlevel/StateMachine.java +++ b/lowlevel_framework/source/src/lowlevel/StateMachine.java @@ -7,9 +7,19 @@ */ public class StateMachine { + public String name; private Set clusters; + private int numInputs; + private int numOutputs; public String getEncoding(){ - + return null; + } + + public int getNumInputs() { + return numInputs; + } + public int getNumOutputs(){ + return numOutputs; } } From 90f27bbc17bb44d6656b82b7750f7efe9bfd17f1 Mon Sep 17 00:00:00 2001 From: theChaoS Date: Sun, 4 Jun 2017 11:34:47 +0200 Subject: [PATCH 04/17] pre test --- lowlevel_framework/source/src/io/StateMachineWriter.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/lowlevel_framework/source/src/io/StateMachineWriter.java b/lowlevel_framework/source/src/io/StateMachineWriter.java index ea83be2..2331fe7 100644 --- a/lowlevel_framework/source/src/io/StateMachineWriter.java +++ b/lowlevel_framework/source/src/io/StateMachineWriter.java @@ -28,8 +28,6 @@ public static void writeFSM(StateMachine fsm, String destination){ bld.append(".end_kiss\n"); bld.append(".latch_order "); // latch mapping - - try (FileWriter out = new FileWriter(destination)) { BufferedWriter buf = new BufferedWriter(out); buf.write(bld.toString()); From fc2033d6779dda9c05fd3c0bec05854a585b783d Mon Sep 17 00:00:00 2001 From: theChaoS Date: Sun, 4 Jun 2017 11:52:14 +0200 Subject: [PATCH 05/17] zwischenstand --- .../source/src/lowlevel/Cluster.java | 11 +++++ .../source/src/lowlevel/Transition.java | 43 +++++++++++++++++++ .../source/src/lowlevel/cluster_encoder.java | 16 +++---- lowlevel_framework/source/src/main/Main.java | 6 ++- 4 files changed, 67 insertions(+), 9 deletions(-) create mode 100644 lowlevel_framework/source/src/lowlevel/Transition.java diff --git a/lowlevel_framework/source/src/lowlevel/Cluster.java b/lowlevel_framework/source/src/lowlevel/Cluster.java index 48eb6e6..eff37fe 100644 --- a/lowlevel_framework/source/src/lowlevel/Cluster.java +++ b/lowlevel_framework/source/src/lowlevel/Cluster.java @@ -10,6 +10,7 @@ public class Cluster { private Set states; + private Set transition; // should be either "binary" or "onehot" private String internalEncoding; @@ -23,6 +24,9 @@ public Cluster(){ } public boolean addState(State state){ + System.out.println("TESST"); + state.getTransitions(); + // this.transition=; return states.add(state); } @@ -57,7 +61,14 @@ public int getNumStates(){ public int getInputs(){ return numInputs; } +/* + public getTransitions(){ + } +*/ + public int getNumOfTransitions(){ + return 0; + } public String getEncodedCluster(){ StringBuilder bld = new StringBuilder(); diff --git a/lowlevel_framework/source/src/lowlevel/Transition.java b/lowlevel_framework/source/src/lowlevel/Transition.java new file mode 100644 index 0000000..0241bf4 --- /dev/null +++ b/lowlevel_framework/source/src/lowlevel/Transition.java @@ -0,0 +1,43 @@ +package lowlevel; + +/** + * Created by theChaoS on 04.06.2017. + */ +public class Transition { + private State targetState; //Ziel + private State originState; + private Cluster targetCluster; + private Cluster originCluster; + + @Override + public Transition(State targetState, State startState, Cluster targetCluster, Cluster startCluster){ + this.targetState=targetState; + this.originState=startState; + this.originCluster=startCluster; + this.targetCluster=targetCluster;//Eine änderung! + } + + @Override + public Transition(State targetState, State startState, Cluster currentCluster){ + this.targetState=targetState; + this.originState=startState; + this.originCluster=currentCluster; + this.targetCluster=currentCluster; + } + + public State getTargetState(){ + return this.targetState; + } + + public State getOriginState(){ + return this.originState; + } + + public Cluster getTargetCluster(){ + return this.targetCluster; + } + + public Cluster getOriginCluster(){ + return this.originCluster; + } +} diff --git a/lowlevel_framework/source/src/lowlevel/cluster_encoder.java b/lowlevel_framework/source/src/lowlevel/cluster_encoder.java index 76a26bf..9a5f466 100644 --- a/lowlevel_framework/source/src/lowlevel/cluster_encoder.java +++ b/lowlevel_framework/source/src/lowlevel/cluster_encoder.java @@ -23,8 +23,8 @@ public ClusterEncoder(){ * @return A mapping of states to strings containing their one-hot value (as chars of {0,1}) * if encoding is not possible (too many states), return null */ - public HashMap encodeOneHot (State[] states, int nIn){ - HashMap result = new HashMap(); + // public HashMap encodeOneHot (State[] states, int nIn){ + // HashMap result = new HashMap(); /* precondition: states have yet been chosen regarding their clusterability @@ -33,7 +33,7 @@ public HashMap encodeOneHot (State[] states, int nIn){ - } +// } /** * Takes the selected states for a cluster, namely in the array states, and packs them into a LUT-feasible @@ -41,17 +41,17 @@ public HashMap encodeOneHot (State[] states, int nIn){ * @param states the states in the cluster * @return A mapping of states to strings containing their binary value (as chars of {0,1}) */ - public HashMap encodeBinary(State[] states, int nIn){ - HashMap result = new HashMap(); - } +// public HashMap encodeBinary(State[] states, int nIn){ +// HashMap result = new HashMap(); +// } } - +/* public class oneHotEncoder extends ClusterEncoder{ } public class binaryEncoder extends clusterEncoder{ -} \ No newline at end of file +}*/ \ No newline at end of file diff --git a/lowlevel_framework/source/src/main/Main.java b/lowlevel_framework/source/src/main/Main.java index 85c3f4f..dc515a1 100644 --- a/lowlevel_framework/source/src/main/Main.java +++ b/lowlevel_framework/source/src/main/Main.java @@ -6,6 +6,8 @@ import java.io.File; import java.io.FilenameFilter; +import lowlevel.Cluster; + /** * Main class * @author Wolf & Gottschling @@ -55,7 +57,9 @@ public boolean accept(File dir, String name) { - // TODO - here you go + // TODO - here you go + + Cluster myCluster = new Cluster(); } else{ From a1cc40bf57384e917c65cda7fe954f1b57f6ccff Mon Sep 17 00:00:00 2001 From: theChaoS Date: Sun, 4 Jun 2017 11:54:50 +0200 Subject: [PATCH 06/17] zwischenstand --- lowlevel_framework/source/src/lowlevel/Transition.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lowlevel_framework/source/src/lowlevel/Transition.java b/lowlevel_framework/source/src/lowlevel/Transition.java index 0241bf4..fd5f356 100644 --- a/lowlevel_framework/source/src/lowlevel/Transition.java +++ b/lowlevel_framework/source/src/lowlevel/Transition.java @@ -14,7 +14,7 @@ public Transition(State targetState, State startState, Cluster targetCluster, Cl this.targetState=targetState; this.originState=startState; this.originCluster=startCluster; - this.targetCluster=targetCluster;//Eine änderung! + this.targetCluster=targetCluster;//Meh mememmemfrgdddgdd } @Override From 854bbbd30cebcec4480b96c2d6bb7c86bee90a8d Mon Sep 17 00:00:00 2001 From: JulianKaeuser Date: Sun, 4 Jun 2017 11:59:28 +0200 Subject: [PATCH 07/17] added stateMachineWriter --- .../source/src/io/StateMachineWriter.java | 82 ++++++++++++++++++- 1 file changed, 80 insertions(+), 2 deletions(-) diff --git a/lowlevel_framework/source/src/io/StateMachineWriter.java b/lowlevel_framework/source/src/io/StateMachineWriter.java index 2331fe7..25a92d2 100644 --- a/lowlevel_framework/source/src/io/StateMachineWriter.java +++ b/lowlevel_framework/source/src/io/StateMachineWriter.java @@ -1,33 +1,80 @@ package io; +import lowlevel.Cluster; +import lowlevel.State; import lowlevel.StateMachine; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Set; /** * Created by Julian Käuser on 03.06.2017. */ public class StateMachineWriter { + /** + * + * @param fsm the StateMachine object to write out + * @param destination the directory (without line separator in the end!) where the written .kiss2 + * file shall be placed + */ public static void writeFSM(StateMachine fsm, String destination){ if (fsm==null || destination==null){ System.out.println("no fsm written - destination or fsm unknown"); return; } + // catch the "fsm-has-no-name"-case + if (fsm.name==null){ + System.out.println("fsm has no name, name set to time+date of execution"); + fsm.name=new SimpleDateFormat("yyyyMMdd_HHmmss").format(Calendar.getInstance().getTime()); + } StringBuilder bld = new StringBuilder(); bld.append("# "+fsm.name +" encoded cluster-wise\n"); + bld.append(".model "+fsm.name); + + // latch initilizations + String[] latches = getLatches(fsm); + for (String l : latches){ + bld.append(".latch "+l+"\n"); + } + + bld.append(".start_kiss"); bld.append(".i "+fsm.getNumInputs()+"\n"); bld.append(".o "+fsm.getNumOutputs()+"\n"); - // states and transitions + //bld.append(".p "+fsm.getNumTransistions()+"\n"); + //bld.append(".s "+fsm.getNumStates()+"\n"); + //bld.append(".r "+fsm.getResetState()); + bld.append(".end_kiss\n"); - bld.append(".latch_order "); // latch mapping + //latch mapping + bld.append(".latch_order "); +<<<<<<< Updated upstream +======= + for (int ii=0; ii>>>>>> Stashed changes try (FileWriter out = new FileWriter(destination)) { BufferedWriter buf = new BufferedWriter(out); buf.write(bld.toString()); @@ -37,4 +84,35 @@ public static void writeFSM(StateMachine fsm, String destination){ e.printStackTrace(); } } + + private static String[] getLatches(StateMachine fsm){ + String[] latches; + if (fsm==null){ + latches = new String[1]; + latches[0] = ""; + return latches; + } + + int + + return latches; + + } + + private static String[] getExternalClusterLatches(StateMachine fsm){ + String[] latches; + Set clusters = fsm.getClusters(); + latches = new String[clusters.size()]; + int ii=0; + for (Cluster cluster : clusters){ + latches[ii] = "v"+cluster.getID()+ " "; + } + return latches; + } + + private static String[] getClusterInternalLatches(Cluster cluster){ + String[] latches; + int len = cluster. + + } } From 1f33a345cbdb93facd1df65dfc4b8bc0aa5c3ff5 Mon Sep 17 00:00:00 2001 From: theChaoS Date: Sun, 4 Jun 2017 12:00:57 +0200 Subject: [PATCH 08/17] zwischenstand --- .../source/src/lowlevel/Transition.java | 4 +--- .../source/src/lowlevel/cluster_encoder.java | 12 ++++++------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/lowlevel_framework/source/src/lowlevel/Transition.java b/lowlevel_framework/source/src/lowlevel/Transition.java index fd5f356..9fbd316 100644 --- a/lowlevel_framework/source/src/lowlevel/Transition.java +++ b/lowlevel_framework/source/src/lowlevel/Transition.java @@ -9,15 +9,13 @@ public class Transition { private Cluster targetCluster; private Cluster originCluster; - @Override public Transition(State targetState, State startState, Cluster targetCluster, Cluster startCluster){ this.targetState=targetState; this.originState=startState; this.originCluster=startCluster; - this.targetCluster=targetCluster;//Meh mememmemfrgdddgdd + this.targetCluster=targetCluster; } - @Override public Transition(State targetState, State startState, Cluster currentCluster){ this.targetState=targetState; this.originState=startState; diff --git a/lowlevel_framework/source/src/lowlevel/cluster_encoder.java b/lowlevel_framework/source/src/lowlevel/cluster_encoder.java index 9a5f466..c4c3b01 100644 --- a/lowlevel_framework/source/src/lowlevel/cluster_encoder.java +++ b/lowlevel_framework/source/src/lowlevel/cluster_encoder.java @@ -23,8 +23,8 @@ public ClusterEncoder(){ * @return A mapping of states to strings containing their one-hot value (as chars of {0,1}) * if encoding is not possible (too many states), return null */ - // public HashMap encodeOneHot (State[] states, int nIn){ - // HashMap result = new HashMap(); + public HashMap encodeOneHot (State[] states, int nIn){ + HashMap result = new HashMap(); /* precondition: states have yet been chosen regarding their clusterability @@ -33,7 +33,7 @@ public ClusterEncoder(){ -// } + } /** * Takes the selected states for a cluster, namely in the array states, and packs them into a LUT-feasible @@ -41,9 +41,9 @@ public ClusterEncoder(){ * @param states the states in the cluster * @return A mapping of states to strings containing their binary value (as chars of {0,1}) */ -// public HashMap encodeBinary(State[] states, int nIn){ -// HashMap result = new HashMap(); -// } + public HashMap encodeBinary(State[] states, int nIn){ + HashMap result = new HashMap(); + } } From fcba6387302fda66272c6f35c312c7bafb274dd3 Mon Sep 17 00:00:00 2001 From: JulianKaeuser Date: Sun, 4 Jun 2017 12:07:14 +0200 Subject: [PATCH 09/17] added stateMachineWriter --- .../source/src/io/StateMachineWriter.java | 15 +++-- .../source/src/lowlevel/Cluster.java | 10 +++- .../source/src/lowlevel/StateMachine.java | 4 ++ .../source/src/lowlevel/cluster_encoder.java | 57 ------------------- 4 files changed, 18 insertions(+), 68 deletions(-) delete mode 100644 lowlevel_framework/source/src/lowlevel/cluster_encoder.java diff --git a/lowlevel_framework/source/src/io/StateMachineWriter.java b/lowlevel_framework/source/src/io/StateMachineWriter.java index 25a92d2..18dca12 100644 --- a/lowlevel_framework/source/src/io/StateMachineWriter.java +++ b/lowlevel_framework/source/src/io/StateMachineWriter.java @@ -57,8 +57,7 @@ public static void writeFSM(StateMachine fsm, String destination){ //latch mapping bld.append(".latch_order "); -<<<<<<< Updated upstream -======= + for (int ii=0; ii>>>>>> Stashed changes + try (FileWriter out = new FileWriter(destination)) { BufferedWriter buf = new BufferedWriter(out); buf.write(bld.toString()); @@ -86,14 +85,13 @@ public static void writeFSM(StateMachine fsm, String destination){ } private static String[] getLatches(StateMachine fsm){ - String[] latches; - if (fsm==null){ + String[] latches = null; + if (fsm==null) { latches = new String[1]; latches[0] = ""; return latches; } - int return latches; @@ -111,8 +109,9 @@ private static String[] getExternalClusterLatches(StateMachine fsm){ } private static String[] getClusterInternalLatches(Cluster cluster){ - String[] latches; - int len = cluster. + String[] latches = null; + int len; + return latches; } } diff --git a/lowlevel_framework/source/src/lowlevel/Cluster.java b/lowlevel_framework/source/src/lowlevel/Cluster.java index eff37fe..aae4384 100644 --- a/lowlevel_framework/source/src/lowlevel/Cluster.java +++ b/lowlevel_framework/source/src/lowlevel/Cluster.java @@ -73,13 +73,13 @@ public int getNumOfTransitions(){ public String getEncodedCluster(){ StringBuilder bld = new StringBuilder(); - ClusterEncoder enc = new ClusterEncoder(); + // ClusterEncoder enc = new ClusterEncoder(); HashMap map = null; switch (getEncoding()) { case "binary": - map = enc.encodeBinary(this.getStateArray(), this.getInputs()); + //map = enc.encodeBinary(this.getStateArray(), this.getInputs()); case "onehot": - map = enc.encodeOneHot(this.getStateArray(), this.getInputs()); + //map = enc.encodeOneHot(this.getStateArray(), this.getInputs()); } for (State s : map.keySet()) { String str = ".code "+s.getName()+" "+map.get(s)+"\n"; @@ -87,4 +87,8 @@ public String getEncodedCluster(){ } return bld.toString(); } + + public String getCode(){ + return ""; + } } diff --git a/lowlevel_framework/source/src/lowlevel/StateMachine.java b/lowlevel_framework/source/src/lowlevel/StateMachine.java index 2d0208c..79f8e3a 100644 --- a/lowlevel_framework/source/src/lowlevel/StateMachine.java +++ b/lowlevel_framework/source/src/lowlevel/StateMachine.java @@ -22,4 +22,8 @@ public int getNumInputs() { public int getNumOutputs(){ return numOutputs; } + + public Set getClusters(){ + return this.clusters; + } } diff --git a/lowlevel_framework/source/src/lowlevel/cluster_encoder.java b/lowlevel_framework/source/src/lowlevel/cluster_encoder.java deleted file mode 100644 index c4c3b01..0000000 --- a/lowlevel_framework/source/src/lowlevel/cluster_encoder.java +++ /dev/null @@ -1,57 +0,0 @@ -package lowlevel; - -import java.util.HashMap; - -/** - * Julians Idee für diese Klasse: Nehme bis zu drei States, und setze ein One-Hot-Encoding ins Slice. - * -> Ergo 3 Flipflops - * Created by theChaoS on 03.06.2017. - */ -public class ClusterEncoder { - final static int k=6; - final static int nFF=4; - - - public ClusterEncoder(){ - - } - - /** - * Takes the selected states for a cluster, namely in the array states, and packs them into a LUT-feasible - * format. Returns the encoding for this state cluster in one hot - * @param states the states in the cluster, each entry non-null - * @return A mapping of states to strings containing their one-hot value (as chars of {0,1}) - * if encoding is not possible (too many states), return null - */ - public HashMap encodeOneHot (State[] states, int nIn){ - HashMap result = new HashMap(); - - /* - precondition: states have yet been chosen regarding their clusterability - */ - - - - - } - - /** - * Takes the selected states for a cluster, namely in the array states, and packs them into a LUT-feasible - * format. Returns the encoding for this state cluster in binary encoding - * @param states the states in the cluster - * @return A mapping of states to strings containing their binary value (as chars of {0,1}) - */ - public HashMap encodeBinary(State[] states, int nIn){ - HashMap result = new HashMap(); - } - -} - -/* -public class oneHotEncoder extends ClusterEncoder{ - -} - -public class binaryEncoder extends clusterEncoder{ - -}*/ \ No newline at end of file From 0fd8798bbbef349e805329531057f470b129591f Mon Sep 17 00:00:00 2001 From: JulianKaeuser Date: Sun, 4 Jun 2017 12:09:46 +0200 Subject: [PATCH 10/17] added stateMachineWriter --- lowlevel_framework/source/src/main/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lowlevel_framework/source/src/main/Main.java b/lowlevel_framework/source/src/main/Main.java index dc515a1..8e59f69 100644 --- a/lowlevel_framework/source/src/main/Main.java +++ b/lowlevel_framework/source/src/main/Main.java @@ -27,7 +27,7 @@ public static void main(String[] args) { File dir = new File(input_file_name); ParsedFile[] inputFiles; - if (args[1]!=null && args[1]=="-all" && dir.isDirectory()){ + if (args[1]!=null && args[1]!=null && args[1]=="-all" && dir.isDirectory()){ // args[0] is a directory, and all files of the directory shall be parsed FilenameFilter filter = new FilenameFilter() { @Override From 6032467ad4aa38cf4e475459471e35a1cede4219 Mon Sep 17 00:00:00 2001 From: JulianKaeuser Date: Sun, 4 Jun 2017 12:11:59 +0200 Subject: [PATCH 11/17] added stateMachineWriter --- lowlevel_framework/source/src/main/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lowlevel_framework/source/src/main/Main.java b/lowlevel_framework/source/src/main/Main.java index 8e59f69..599e417 100644 --- a/lowlevel_framework/source/src/main/Main.java +++ b/lowlevel_framework/source/src/main/Main.java @@ -27,7 +27,7 @@ public static void main(String[] args) { File dir = new File(input_file_name); ParsedFile[] inputFiles; - if (args[1]!=null && args[1]!=null && args[1]=="-all" && dir.isDirectory()){ + if (args.length>1 && args[1]!=null && args[1]=="-all" && dir.isDirectory()){ // args[0] is a directory, and all files of the directory shall be parsed FilenameFilter filter = new FilenameFilter() { @Override From 79c949312ff5185a72d015b43a2441543c902649 Mon Sep 17 00:00:00 2001 From: JulianKaeuser Date: Sun, 4 Jun 2017 13:18:49 +0200 Subject: [PATCH 12/17] added stateMachineWriter --- .../source/src/io/StateMachineWriter.java | 10 +++++++++- lowlevel_framework/source/src/main/Main.java | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lowlevel_framework/source/src/io/StateMachineWriter.java b/lowlevel_framework/source/src/io/StateMachineWriter.java index 18dca12..4fe3be2 100644 --- a/lowlevel_framework/source/src/io/StateMachineWriter.java +++ b/lowlevel_framework/source/src/io/StateMachineWriter.java @@ -20,7 +20,7 @@ public class StateMachineWriter { /** * * @param fsm the StateMachine object to write out - * @param destination the directory (without line separator in the end!) where the written .kiss2 + * @param destination the directory where the written .kiss2 * file shall be placed */ public static void writeFSM(StateMachine fsm, String destination){ @@ -38,6 +38,8 @@ public static void writeFSM(StateMachine fsm, String destination){ bld.append("# "+fsm.name +" encoded cluster-wise\n"); bld.append(".model "+fsm.name); + bld.append(buildInputs(fsm)); + // latch initilizations String[] latches = getLatches(fsm); for (String l : latches){ @@ -114,4 +116,10 @@ private static String[] getClusterInternalLatches(Cluster cluster){ return latches; } + + private static String buildInputs(StateMachine fsm){ + String ins = ""; + + + } } diff --git a/lowlevel_framework/source/src/main/Main.java b/lowlevel_framework/source/src/main/Main.java index 599e417..a3eed9e 100644 --- a/lowlevel_framework/source/src/main/Main.java +++ b/lowlevel_framework/source/src/main/Main.java @@ -61,6 +61,8 @@ public boolean accept(File dir, String name) { Cluster myCluster = new Cluster(); + //use StateMachineWriter here to generate output file (BLIF) + } else{ System.out.println("No input argument given"); From e59dcbef56e0b25496cef4a10c5f9c1d3da48476 Mon Sep 17 00:00:00 2001 From: JulianKaeuser Date: Sun, 4 Jun 2017 13:20:30 +0200 Subject: [PATCH 13/17] additions to StateMachineWriter --- lowlevel_framework/source/src/io/StateMachineWriter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lowlevel_framework/source/src/io/StateMachineWriter.java b/lowlevel_framework/source/src/io/StateMachineWriter.java index 4fe3be2..df5ecb6 100644 --- a/lowlevel_framework/source/src/io/StateMachineWriter.java +++ b/lowlevel_framework/source/src/io/StateMachineWriter.java @@ -119,7 +119,7 @@ private static String[] getClusterInternalLatches(Cluster cluster){ private static String buildInputs(StateMachine fsm){ String ins = ""; - + return ins; } } From 403b2f3d60a950f19cd98f38926cc26d7ff63be0 Mon Sep 17 00:00:00 2001 From: theChaoS Date: Sun, 4 Jun 2017 13:24:27 +0200 Subject: [PATCH 14/17] zwischenstand --- lowlevel_framework/source/src/main/Main.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lowlevel_framework/source/src/main/Main.java b/lowlevel_framework/source/src/main/Main.java index a3eed9e..39e016b 100644 --- a/lowlevel_framework/source/src/main/Main.java +++ b/lowlevel_framework/source/src/main/Main.java @@ -60,9 +60,7 @@ public boolean accept(File dir, String name) { // TODO - here you go Cluster myCluster = new Cluster(); - - //use StateMachineWriter here to generate output file (BLIF) - + myCluster.addState(fsm.getInitialState()); //DAS kommentar !!! } else{ System.out.println("No input argument given"); From 426e041c958e01a7e1d7d3f0860013f1338a614d Mon Sep 17 00:00:00 2001 From: theChaoS Date: Sat, 3 Jun 2017 13:34:54 +0200 Subject: [PATCH 15/17] Cluster created --- .../source/src/lowlevel/Cluster.java | 87 +++++-------------- 1 file changed, 21 insertions(+), 66 deletions(-) diff --git a/lowlevel_framework/source/src/lowlevel/Cluster.java b/lowlevel_framework/source/src/lowlevel/Cluster.java index aae4384..b492015 100644 --- a/lowlevel_framework/source/src/lowlevel/Cluster.java +++ b/lowlevel_framework/source/src/lowlevel/Cluster.java @@ -1,94 +1,49 @@ package lowlevel; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Set; +import lowlevel.State; + +import java.util.ArrayList; +import java.util.List; /** - * Created by Julian Käuser on 03.06.2017. + * Created by theChaoS on 03.06.2017. */ public class Cluster { + private List myStates; + private List - private Set states; - private Set transition; - - // should be either "binary" or "onehot" - private String internalEncoding; - - private long id; - - private int numInputs; - + @Override public Cluster(){ - states = new HashSet(); + this.myStates= new ArrayList(); } - public boolean addState(State state){ - System.out.println("TESST"); - state.getTransitions(); - // this.transition=; - return states.add(state); + @Override + public Cluster(ArrayList states){ + this.myStates=states; } - public State[] getStateArray(){ - return (State[]) states.toArray(); - } - public boolean removeState(State state){ - return states.remove(state); - } + public void addState(State aState){ + this.myStates.add(aState); + for(State state : this.myStates){ + state + } - public String getEncoding(){ - return internalEncoding; } - public void setEncoding(String enc){ - internalEncoding=enc; - } + public getAllStates(){ - public void setID(long id){ - this.id = id; } - public long getID(){ - return id; - } + public getOutgoingTransactions(){ - public int getNumStates(){ - return states.size(); } - public int getInputs(){ - return numInputs; - } -/* - public getTransitions(){ + public getIngoingTransactions(){ } -*/ - public int getNumOfTransitions(){ - return 0; - } - public String getEncodedCluster(){ - StringBuilder bld = new StringBuilder(); - - // ClusterEncoder enc = new ClusterEncoder(); - HashMap map = null; - switch (getEncoding()) { - case "binary": - //map = enc.encodeBinary(this.getStateArray(), this.getInputs()); - case "onehot": - //map = enc.encodeOneHot(this.getStateArray(), this.getInputs()); - } - for (State s : map.keySet()) { - String str = ".code "+s.getName()+" "+map.get(s)+"\n"; - bld.append(str); - } - return bld.toString(); - } + public getTransactions(){ - public String getCode(){ - return ""; } } From 8b88df1d65858d81ea3f8b4e7026e0268647f2d6 Mon Sep 17 00:00:00 2001 From: JulianKaeuser Date: Sat, 3 Jun 2017 18:34:14 +0200 Subject: [PATCH 16/17] Introduced Cluster, StateMachine, StateMachineWriter --- .../source/src/lowlevel/Cluster.java | 74 +++++++++++++------ .../source/src/lowlevel/StateMachine.java | 16 +--- .../source/src/lowlevel/cluster_encoder.java | 57 ++++++++++++++ lowlevel_framework/source/src/main/Main.java | 8 +- 4 files changed, 112 insertions(+), 43 deletions(-) create mode 100644 lowlevel_framework/source/src/lowlevel/cluster_encoder.java diff --git a/lowlevel_framework/source/src/lowlevel/Cluster.java b/lowlevel_framework/source/src/lowlevel/Cluster.java index b492015..3e6c457 100644 --- a/lowlevel_framework/source/src/lowlevel/Cluster.java +++ b/lowlevel_framework/source/src/lowlevel/Cluster.java @@ -1,49 +1,79 @@ package lowlevel; -import lowlevel.State; - -import java.util.ArrayList; -import java.util.List; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; /** - * Created by theChaoS on 03.06.2017. + * Created by Julian Käuser on 03.06.2017. */ public class Cluster { - private List myStates; - private List - @Override + private Set states; + + // should be either "binary" or "onehot" + private String internalEncoding; + + private int id; + + private int numInputs; + public Cluster(){ - this.myStates= new ArrayList(); + states = new HashSet(); } - @Override - public Cluster(ArrayList states){ - this.myStates=states; + public boolean addState(State state){ + return states.add(state); } + public State[] getStateArray(){ + return (State[]) states.toArray(); + } - public void addState(State aState){ - this.myStates.add(aState); - for(State state : this.myStates){ - state - } - + public boolean removeState(State state){ + return states.remove(state); } - public getAllStates(){ + public String getEncoding(){ + return internalEncoding; + } + public void setEncoding(String enc){ + internalEncoding=enc; } - public getOutgoingTransactions(){ + public void setID(int id){ + this.id = id; + } + public int getID(){ + return id; } - public getIngoingTransactions(){ + public int getNumStates(){ + return states.size(); + } + public int getInputs(){ + return numInputs; } +} - public getTransactions(){ + public String getEncodedCluster(){ + StringBuilder bld = new StringBuilder(); + ClusterEncoder enc = new ClusterEncoder(); + HashMap map = null; + switch (getEncoding()) { + case "binary": + map = enc.encodeBinary(this.getStateArray(), this.getInputs()); + case "onehot": + map = enc.encodeOneHot(this.getStateArray(), this.getInputs()); + } + for (State s : map.keySet()) { + String str = ".code "+s.getName()+" "+map.get(s)+"\n"; + bld.append(str); + } + return bld.toString(); } } diff --git a/lowlevel_framework/source/src/lowlevel/StateMachine.java b/lowlevel_framework/source/src/lowlevel/StateMachine.java index 79f8e3a..b4fcc8d 100644 --- a/lowlevel_framework/source/src/lowlevel/StateMachine.java +++ b/lowlevel_framework/source/src/lowlevel/StateMachine.java @@ -7,23 +7,9 @@ */ public class StateMachine { - public String name; private Set clusters; - private int numInputs; - private int numOutputs; public String getEncoding(){ - return null; - } - - public int getNumInputs() { - return numInputs; - } - public int getNumOutputs(){ - return numOutputs; - } - - public Set getClusters(){ - return this.clusters; + } } diff --git a/lowlevel_framework/source/src/lowlevel/cluster_encoder.java b/lowlevel_framework/source/src/lowlevel/cluster_encoder.java new file mode 100644 index 0000000..76a26bf --- /dev/null +++ b/lowlevel_framework/source/src/lowlevel/cluster_encoder.java @@ -0,0 +1,57 @@ +package lowlevel; + +import java.util.HashMap; + +/** + * Julians Idee für diese Klasse: Nehme bis zu drei States, und setze ein One-Hot-Encoding ins Slice. + * -> Ergo 3 Flipflops + * Created by theChaoS on 03.06.2017. + */ +public class ClusterEncoder { + final static int k=6; + final static int nFF=4; + + + public ClusterEncoder(){ + + } + + /** + * Takes the selected states for a cluster, namely in the array states, and packs them into a LUT-feasible + * format. Returns the encoding for this state cluster in one hot + * @param states the states in the cluster, each entry non-null + * @return A mapping of states to strings containing their one-hot value (as chars of {0,1}) + * if encoding is not possible (too many states), return null + */ + public HashMap encodeOneHot (State[] states, int nIn){ + HashMap result = new HashMap(); + + /* + precondition: states have yet been chosen regarding their clusterability + */ + + + + + } + + /** + * Takes the selected states for a cluster, namely in the array states, and packs them into a LUT-feasible + * format. Returns the encoding for this state cluster in binary encoding + * @param states the states in the cluster + * @return A mapping of states to strings containing their binary value (as chars of {0,1}) + */ + public HashMap encodeBinary(State[] states, int nIn){ + HashMap result = new HashMap(); + } + +} + + +public class oneHotEncoder extends ClusterEncoder{ + +} + +public class binaryEncoder extends clusterEncoder{ + +} \ No newline at end of file diff --git a/lowlevel_framework/source/src/main/Main.java b/lowlevel_framework/source/src/main/Main.java index 39e016b..85c3f4f 100644 --- a/lowlevel_framework/source/src/main/Main.java +++ b/lowlevel_framework/source/src/main/Main.java @@ -6,8 +6,6 @@ import java.io.File; import java.io.FilenameFilter; -import lowlevel.Cluster; - /** * Main class * @author Wolf & Gottschling @@ -27,7 +25,7 @@ public static void main(String[] args) { File dir = new File(input_file_name); ParsedFile[] inputFiles; - if (args.length>1 && args[1]!=null && args[1]=="-all" && dir.isDirectory()){ + if (args[1]!=null && args[1]=="-all" && dir.isDirectory()){ // args[0] is a directory, and all files of the directory shall be parsed FilenameFilter filter = new FilenameFilter() { @Override @@ -57,10 +55,8 @@ public boolean accept(File dir, String name) { - // TODO - here you go + // TODO - here you go - Cluster myCluster = new Cluster(); - myCluster.addState(fsm.getInitialState()); //DAS kommentar !!! } else{ System.out.println("No input argument given"); From f3d5c561f81c6669cd2a6be4e7ca92bde09d3905 Mon Sep 17 00:00:00 2001 From: theChaoS Date: Sun, 4 Jun 2017 13:59:24 +0200 Subject: [PATCH 17/17] 14 Uhr abgabge --- .../source/src/lowlevel/Cluster.java | 40 +++++++++++++++---- .../source/src/lowlevel/State.java | 6 +-- .../source/src/lowlevel/Transition.java | 16 +++++++- lowlevel_framework/source/src/main/Main.java | 8 +++- 4 files changed, 55 insertions(+), 15 deletions(-) diff --git a/lowlevel_framework/source/src/lowlevel/Cluster.java b/lowlevel_framework/source/src/lowlevel/Cluster.java index 3e6c457..206884f 100644 --- a/lowlevel_framework/source/src/lowlevel/Cluster.java +++ b/lowlevel_framework/source/src/lowlevel/Cluster.java @@ -10,19 +10,32 @@ public class Cluster { private Set states; + private Set transitions; // should be either "binary" or "onehot" private String internalEncoding; - private int id; + private long id; private int numInputs; public Cluster(){ - states = new HashSet(); + this.states = new HashSet(); + this.transitions = new HashSet(); } public boolean addState(State state){ + // System.out.println("-----TEST-----"); + long[][] crappy_transitions= state.getTransitions(); + //ACHTUNG, war NICHT dokumentiert und ist super unsicher + for(int i=0;i getTransitions(){ + return this.transitions; + } + + public int getNumOfTransitions(){ + return this.transitions.size(); + } public String getEncodedCluster(){ StringBuilder bld = new StringBuilder(); - ClusterEncoder enc = new ClusterEncoder(); + // ClusterEncoder enc = new ClusterEncoder(); HashMap map = null; switch (getEncoding()) { case "binary": - map = enc.encodeBinary(this.getStateArray(), this.getInputs()); + //map = enc.encodeBinary(this.getStateArray(), this.getInputs()); case "onehot": - map = enc.encodeOneHot(this.getStateArray(), this.getInputs()); + //map = enc.encodeOneHot(this.getStateArray(), this.getInputs()); } for (State s : map.keySet()) { String str = ".code "+s.getName()+" "+map.get(s)+"\n"; @@ -76,4 +96,8 @@ public String getEncodedCluster(){ } return bld.toString(); } + + public String getCode(){ + return ""; + } } diff --git a/lowlevel_framework/source/src/lowlevel/State.java b/lowlevel_framework/source/src/lowlevel/State.java index fc4ea86..0aa1095 100644 --- a/lowlevel_framework/source/src/lowlevel/State.java +++ b/lowlevel_framework/source/src/lowlevel/State.java @@ -129,9 +129,9 @@ public long[][] getTransitions(){ int i=0; for(Map.Entry entry : nextStateMap.entrySet()){ - transitions[i][0] = this.code; - transitions[i][1] = entry.getKey(); - transitions[i][2] = entry.getValue().getCode(); + transitions[i][0] = this.code; //current State in code ? + transitions[i][1] = entry.getKey(); //Input Code ? + transitions[i][2] = entry.getValue().getCode(); //next State Code ? i++; } diff --git a/lowlevel_framework/source/src/lowlevel/Transition.java b/lowlevel_framework/source/src/lowlevel/Transition.java index 9fbd316..1c76116 100644 --- a/lowlevel_framework/source/src/lowlevel/Transition.java +++ b/lowlevel_framework/source/src/lowlevel/Transition.java @@ -4,25 +4,37 @@ * Created by theChaoS on 04.06.2017. */ public class Transition { + private long input; + private State targetState; //Ziel private State originState; private Cluster targetCluster; private Cluster originCluster; - public Transition(State targetState, State startState, Cluster targetCluster, Cluster startCluster){ + public Transition(long input, State targetState, State startState, Cluster targetCluster, Cluster startCluster){ + this.input=input; this.targetState=targetState; this.originState=startState; this.originCluster=startCluster; this.targetCluster=targetCluster; } - public Transition(State targetState, State startState, Cluster currentCluster){ + public Transition(long input, State targetState, State startState, Cluster currentCluster){ + this.input=input; this.targetState=targetState; this.originState=startState; this.originCluster=currentCluster; this.targetCluster=currentCluster; } + public long getInput(){ + return this.input; + } + + public String getInputAsBinnary(){ + return Long.toBinaryString(this.input); + } + public State getTargetState(){ return this.targetState; } diff --git a/lowlevel_framework/source/src/main/Main.java b/lowlevel_framework/source/src/main/Main.java index 85c3f4f..48d4c56 100644 --- a/lowlevel_framework/source/src/main/Main.java +++ b/lowlevel_framework/source/src/main/Main.java @@ -6,6 +6,8 @@ import java.io.File; import java.io.FilenameFilter; +import lowlevel.Cluster; + /** * Main class * @author Wolf & Gottschling @@ -25,7 +27,7 @@ public static void main(String[] args) { File dir = new File(input_file_name); ParsedFile[] inputFiles; - if (args[1]!=null && args[1]=="-all" && dir.isDirectory()){ + if (args.length>1 && args[1]!=null && args[1]=="-all" && dir.isDirectory()){ // args[0] is a directory, and all files of the directory shall be parsed FilenameFilter filter = new FilenameFilter() { @Override @@ -55,8 +57,10 @@ public boolean accept(File dir, String name) { - // TODO - here you go + // TODO - here you go + Cluster myCluster = new Cluster(); + myCluster.addState(fsm.getStates()[0]); //DAS kommentar !!! } else{ System.out.println("No input argument given");