فهرست منبع

bugfixing LaTeX

rparedis 4 سال پیش
والد
کامیت
5df02370af

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 92 - 17
examples/notebook/HybridTrain.ipynb


+ 51 - 51
examples/notebook/accODE.dot

@@ -5,56 +5,56 @@ digraph model {
  label=<<B>accODE (CBD)</B>>;
  labelloc="t";
  fontsize=20;
- node_139653226402288 [label="v", shape=none];
- inter_139653222133328_OUT1 -> node_139653226402288 [headlabel="", arrowhead="normal", arrowtail="none", dir=both];
- node_139653222132320 [label="x", shape=none];
- inter_139653222133328_OUT2 -> node_139653222132320 [headlabel="", arrowhead="normal", arrowtail="none", dir=both];
- node_139653222133328 [label="CBD\n(RK)", shape=Msquare];
- inter_139653223132608_OUT1 -> node_139653222133328 [headlabel="v0", arrowhead="normal", arrowtail="none", dir=both];
- inter_139653223130928_OUT1 -> node_139653222133328 [headlabel="k", arrowhead="normal", arrowtail="none", dir=both];
- inter_139653221163984_time -> node_139653222133328 [headlabel="time", arrowhead="normal", arrowtail="none", dir=both];
- inter_139653221163984_rel_time -> node_139653222133328 [headlabel="rel_time", arrowhead="normal", arrowtail="none", dir=both];
- inter_139653221163984_delta -> node_139653222133328 [headlabel="h", arrowhead="normal", arrowtail="none", dir=both];
- inter_139653223132608_OUT1 -> node_139653222133328 [headlabel="IC1", arrowhead="normal", arrowtail="none", dir=both];
- inter_139653223132992_OUT1 -> node_139653222133328 [headlabel="IC2", arrowhead="normal", arrowtail="none", dir=both];
- inter_139653222133328_OUT1 [shape=point, width=0.01, height=0.01];
- node_139653222133328 -> inter_139653222133328_OUT1 [taillabel="OUT1", arrowtail="invempty", arrowhead="none", dir=both];
- inter_139653222133328_OUT2 [shape=point, width=0.01, height=0.01];
- node_139653222133328 -> inter_139653222133328_OUT2 [taillabel="OUT2", arrowtail="invempty", arrowhead="none", dir=both];
- inter_139653222133328_h_new [shape=point, width=0.01, height=0.01];
- node_139653222133328 -> inter_139653222133328_h_new [taillabel="h_new", arrowtail="invempty", arrowhead="none", dir=both];
- node_139653221163984 [label="Clock\n(clock)", shape=Msquare];
- inter_139653225201968_OUT1 -> node_139653221163984 [headlabel="h", arrowhead="normal", arrowtail="none", dir=both];
- inter_139653221163984_time [shape=point, width=0.01, height=0.01];
- node_139653221163984 -> inter_139653221163984_time [taillabel="time", arrowtail="invempty", arrowhead="none", dir=both];
- inter_139653221163984_rel_time [shape=point, width=0.01, height=0.01];
- node_139653221163984 -> inter_139653221163984_rel_time [taillabel="rel_time", arrowtail="invempty", arrowhead="none", dir=both];
- inter_139653221163984_delta [shape=point, width=0.01, height=0.01];
- node_139653221163984 -> inter_139653221163984_delta [taillabel="delta", arrowtail="invempty", arrowhead="none", dir=both];
- node_139653216704688 [label=" ConstantBlock\n(HIC)\n0.1", shape=ellipse];
- inter_139653216704688_OUT1 [shape=point, width=0.01, height=0.01];
- node_139653216704688 -> inter_139653216704688_OUT1 [taillabel="OUT1", arrowtail="invempty", arrowhead="none", dir=both];
- node_139653223132368 [label="DelayBlock\n(HDelay)", shape=box];
- inter_139653222133328_h_new -> node_139653223132368 [headlabel="IN1", arrowhead="normal", arrowtail="none", dir=both];
- inter_139653216704688_OUT1 -> node_139653223132368 [headlabel="IC", arrowhead="normal", arrowtail="none", dir=both];
- inter_139653223132368_OUT1 [shape=point, width=0.01, height=0.01];
- node_139653223132368 -> inter_139653223132368_OUT1 [taillabel="OUT1", arrowtail="invempty", arrowhead="none", dir=both];
- node_139653223132992 [label=" ConstantBlock\n(x0)\n0.0", shape=ellipse];
- inter_139653223132992_OUT1 [shape=point, width=0.01, height=0.01];
- node_139653223132992 -> inter_139653223132992_OUT1 [taillabel="OUT1", arrowtail="invempty", arrowhead="none", dir=both];
- node_139653223132608 [label=" ConstantBlock\n(v0)\n0.0", shape=ellipse];
- inter_139653223132608_OUT1 [shape=point, width=0.01, height=0.01];
- node_139653223132608 -> inter_139653223132608_OUT1 [taillabel="OUT1", arrowtail="invempty", arrowhead="none", dir=both];
- node_139653223130928 [label=" ConstantBlock\n(k)\n0.05", shape=ellipse];
- inter_139653223130928_OUT1 [shape=point, width=0.01, height=0.01];
- node_139653223130928 -> inter_139653223130928_OUT1 [taillabel="OUT1", arrowtail="invempty", arrowhead="none", dir=both];
- node_139653225652480 [label=" ConstantBlock\n(H)\ninf", shape=ellipse];
- inter_139653225652480_OUT1 [shape=point, width=0.01, height=0.01];
- node_139653225652480 -> inter_139653225652480_OUT1 [taillabel="OUT1", arrowtail="invempty", arrowhead="none", dir=both];
- node_139653225201968 [label="MinBlock\n(Min)", shape=box];
- inter_139653225652480_OUT1 -> node_139653225201968 [headlabel="IN1", arrowhead="normal", arrowtail="none", dir=both];
- inter_139653223132368_OUT1 -> node_139653225201968 [headlabel="IN2", arrowhead="normal", arrowtail="none", dir=both];
- inter_139653225201968_OUT1 [shape=point, width=0.01, height=0.01];
- node_139653225201968 -> inter_139653225201968_OUT1 [taillabel="OUT1", arrowtail="invempty", arrowhead="none", dir=both];
+ node_219552592 [label="v", shape=none];
+ inter_220357072_OUT1 -> node_219552592 [headlabel="", arrowhead="normal", arrowtail="none", dir=both];
+ node_219552880 [label="x", shape=none];
+ inter_220357072_OUT2 -> node_219552880 [headlabel="", arrowhead="normal", arrowtail="none", dir=both];
+ node_220357072 [label="CBD\n(RK)", shape=Msquare];
+ inter_221643728_OUT1 -> node_220357072 [headlabel="v0", arrowhead="normal", arrowtail="none", dir=both];
+ inter_219372656_OUT1 -> node_220357072 [headlabel="k", arrowhead="normal", arrowtail="none", dir=both];
+ inter_219692784_time -> node_220357072 [headlabel="time", arrowhead="normal", arrowtail="none", dir=both];
+ inter_219692784_rel_time -> node_220357072 [headlabel="rel_time", arrowhead="normal", arrowtail="none", dir=both];
+ inter_219692784_delta -> node_220357072 [headlabel="h", arrowhead="normal", arrowtail="none", dir=both];
+ inter_221643728_OUT1 -> node_220357072 [headlabel="IC1", arrowhead="normal", arrowtail="none", dir=both];
+ inter_222825648_OUT1 -> node_220357072 [headlabel="IC2", arrowhead="normal", arrowtail="none", dir=both];
+ inter_220357072_OUT1 [shape=point, width=0.01, height=0.01];
+ node_220357072 -> inter_220357072_OUT1 [taillabel="OUT1", arrowtail="invempty", arrowhead="none", dir=both];
+ inter_220357072_OUT2 [shape=point, width=0.01, height=0.01];
+ node_220357072 -> inter_220357072_OUT2 [taillabel="OUT2", arrowtail="invempty", arrowhead="none", dir=both];
+ inter_220357072_h_new [shape=point, width=0.01, height=0.01];
+ node_220357072 -> inter_220357072_h_new [taillabel="h_new", arrowtail="invempty", arrowhead="none", dir=both];
+ node_219692784 [label="Clock\n(clock)", shape=Msquare];
+ inter_219365520_OUT1 -> node_219692784 [headlabel="h", arrowhead="normal", arrowtail="none", dir=both];
+ inter_219692784_time [shape=point, width=0.01, height=0.01];
+ node_219692784 -> inter_219692784_time [taillabel="time", arrowtail="invempty", arrowhead="none", dir=both];
+ inter_219692784_rel_time [shape=point, width=0.01, height=0.01];
+ node_219692784 -> inter_219692784_rel_time [taillabel="rel_time", arrowtail="invempty", arrowhead="none", dir=both];
+ inter_219692784_delta [shape=point, width=0.01, height=0.01];
+ node_219692784 -> inter_219692784_delta [taillabel="delta", arrowtail="invempty", arrowhead="none", dir=both];
+ node_221918896 [label=" ConstantBlock\n(HIC)\n0.1", shape=ellipse];
+ inter_221918896_OUT1 [shape=point, width=0.01, height=0.01];
+ node_221918896 -> inter_221918896_OUT1 [taillabel="OUT1", arrowtail="invempty", arrowhead="none", dir=both];
+ node_221828560 [label="DelayBlock\n(HDelay)", shape=box];
+ inter_220357072_h_new -> node_221828560 [headlabel="IN1", arrowhead="normal", arrowtail="none", dir=both];
+ inter_221918896_OUT1 -> node_221828560 [headlabel="IC", arrowhead="normal", arrowtail="none", dir=both];
+ inter_221828560_OUT1 [shape=point, width=0.01, height=0.01];
+ node_221828560 -> inter_221828560_OUT1 [taillabel="OUT1", arrowtail="invempty", arrowhead="none", dir=both];
+ node_222825648 [label=" ConstantBlock\n(x0)\n0.0", shape=ellipse];
+ inter_222825648_OUT1 [shape=point, width=0.01, height=0.01];
+ node_222825648 -> inter_222825648_OUT1 [taillabel="OUT1", arrowtail="invempty", arrowhead="none", dir=both];
+ node_221643728 [label=" ConstantBlock\n(v0)\n0.0", shape=ellipse];
+ inter_221643728_OUT1 [shape=point, width=0.01, height=0.01];
+ node_221643728 -> inter_221643728_OUT1 [taillabel="OUT1", arrowtail="invempty", arrowhead="none", dir=both];
+ node_219372656 [label=" ConstantBlock\n(k)\n0.05", shape=ellipse];
+ inter_219372656_OUT1 [shape=point, width=0.01, height=0.01];
+ node_219372656 -> inter_219372656_OUT1 [taillabel="OUT1", arrowtail="invempty", arrowhead="none", dir=both];
+ node_221643376 [label=" ConstantBlock\n(H)\ninf", shape=ellipse];
+ inter_221643376_OUT1 [shape=point, width=0.01, height=0.01];
+ node_221643376 -> inter_221643376_OUT1 [taillabel="OUT1", arrowtail="invempty", arrowhead="none", dir=both];
+ node_219365520 [label="MinBlock\n(Min)", shape=box];
+ inter_221643376_OUT1 -> node_219365520 [headlabel="IN1", arrowhead="normal", arrowtail="none", dir=both];
+ inter_221828560_OUT1 -> node_219365520 [headlabel="IN2", arrowhead="normal", arrowtail="none", dir=both];
+ inter_219365520_OUT1 [shape=point, width=0.01, height=0.01];
+ node_219365520 -> inter_219365520_OUT1 [taillabel="OUT1", arrowtail="invempty", arrowhead="none", dir=both];
 
 }

+ 50 - 50
examples/notebook/fricODE.dot

@@ -5,55 +5,55 @@ digraph model {
  label=<<B>fricODE (CBD)</B>>;
  labelloc="t";
  fontsize=20;
- node_139653222661040 [label="v", shape=none];
- inter_139653222933264_OUT1 -> node_139653222661040 [headlabel="", arrowhead="normal", arrowtail="none", dir=both];
- node_139653219067360 [label="x", shape=none];
- inter_139653222933264_OUT2 -> node_139653219067360 [headlabel="", arrowhead="normal", arrowtail="none", dir=both];
- node_139653222933264 [label="CBD\n(RK)", shape=Msquare];
- inter_139653219417776_OUT1 -> node_139653222933264 [headlabel="k", arrowhead="normal", arrowtail="none", dir=both];
- inter_139653216819760_time -> node_139653222933264 [headlabel="time", arrowhead="normal", arrowtail="none", dir=both];
- inter_139653216819760_rel_time -> node_139653222933264 [headlabel="rel_time", arrowhead="normal", arrowtail="none", dir=both];
- inter_139653216819760_delta -> node_139653222933264 [headlabel="h", arrowhead="normal", arrowtail="none", dir=both];
- inter_139653219414896_OUT1 -> node_139653222933264 [headlabel="IC1", arrowhead="normal", arrowtail="none", dir=both];
- inter_139653224808608_OUT1 -> node_139653222933264 [headlabel="IC2", arrowhead="normal", arrowtail="none", dir=both];
- inter_139653222933264_OUT1 [shape=point, width=0.01, height=0.01];
- node_139653222933264 -> inter_139653222933264_OUT1 [taillabel="OUT1", arrowtail="invempty", arrowhead="none", dir=both];
- inter_139653222933264_OUT2 [shape=point, width=0.01, height=0.01];
- node_139653222933264 -> inter_139653222933264_OUT2 [taillabel="OUT2", arrowtail="invempty", arrowhead="none", dir=both];
- inter_139653222933264_h_new [shape=point, width=0.01, height=0.01];
- node_139653222933264 -> inter_139653222933264_h_new [taillabel="h_new", arrowtail="invempty", arrowhead="none", dir=both];
- node_139653216819760 [label="Clock\n(clock)", shape=Msquare];
- inter_139653223797472_OUT1 -> node_139653216819760 [headlabel="h", arrowhead="normal", arrowtail="none", dir=both];
- inter_139653216819760_time [shape=point, width=0.01, height=0.01];
- node_139653216819760 -> inter_139653216819760_time [taillabel="time", arrowtail="invempty", arrowhead="none", dir=both];
- inter_139653216819760_rel_time [shape=point, width=0.01, height=0.01];
- node_139653216819760 -> inter_139653216819760_rel_time [taillabel="rel_time", arrowtail="invempty", arrowhead="none", dir=both];
- inter_139653216819760_delta [shape=point, width=0.01, height=0.01];
- node_139653216819760 -> inter_139653216819760_delta [taillabel="delta", arrowtail="invempty", arrowhead="none", dir=both];
- node_139653220725520 [label=" ConstantBlock\n(HIC)\n0.1", shape=ellipse];
- inter_139653220725520_OUT1 [shape=point, width=0.01, height=0.01];
- node_139653220725520 -> inter_139653220725520_OUT1 [taillabel="OUT1", arrowtail="invempty", arrowhead="none", dir=both];
- node_139653222070400 [label="DelayBlock\n(HDelay)", shape=box];
- inter_139653222933264_h_new -> node_139653222070400 [headlabel="IN1", arrowhead="normal", arrowtail="none", dir=both];
- inter_139653220725520_OUT1 -> node_139653222070400 [headlabel="IC", arrowhead="normal", arrowtail="none", dir=both];
- inter_139653222070400_OUT1 [shape=point, width=0.01, height=0.01];
- node_139653222070400 -> inter_139653222070400_OUT1 [taillabel="OUT1", arrowtail="invempty", arrowhead="none", dir=both];
- node_139653224808608 [label=" ConstantBlock\n(x0)\n0.0", shape=ellipse];
- inter_139653224808608_OUT1 [shape=point, width=0.01, height=0.01];
- node_139653224808608 -> inter_139653224808608_OUT1 [taillabel="OUT1", arrowtail="invempty", arrowhead="none", dir=both];
- node_139653219414896 [label=" ConstantBlock\n(v0)\n0.0", shape=ellipse];
- inter_139653219414896_OUT1 [shape=point, width=0.01, height=0.01];
- node_139653219414896 -> inter_139653219414896_OUT1 [taillabel="OUT1", arrowtail="invempty", arrowhead="none", dir=both];
- node_139653219417776 [label=" ConstantBlock\n(k)\n0.03", shape=ellipse];
- inter_139653219417776_OUT1 [shape=point, width=0.01, height=0.01];
- node_139653219417776 -> inter_139653219417776_OUT1 [taillabel="OUT1", arrowtail="invempty", arrowhead="none", dir=both];
- node_139653219414464 [label=" ConstantBlock\n(H)\ninf", shape=ellipse];
- inter_139653219414464_OUT1 [shape=point, width=0.01, height=0.01];
- node_139653219414464 -> inter_139653219414464_OUT1 [taillabel="OUT1", arrowtail="invempty", arrowhead="none", dir=both];
- node_139653223797472 [label="MinBlock\n(Min)", shape=box];
- inter_139653219414464_OUT1 -> node_139653223797472 [headlabel="IN1", arrowhead="normal", arrowtail="none", dir=both];
- inter_139653222070400_OUT1 -> node_139653223797472 [headlabel="IN2", arrowhead="normal", arrowtail="none", dir=both];
- inter_139653223797472_OUT1 [shape=point, width=0.01, height=0.01];
- node_139653223797472 -> inter_139653223797472_OUT1 [taillabel="OUT1", arrowtail="invempty", arrowhead="none", dir=both];
+ node_219186512 [label="v", shape=none];
+ inter_219342608_OUT1 -> node_219186512 [headlabel="", arrowhead="normal", arrowtail="none", dir=both];
+ node_220161328 [label="x", shape=none];
+ inter_219342608_OUT2 -> node_220161328 [headlabel="", arrowhead="normal", arrowtail="none", dir=both];
+ node_219342608 [label="CBD\n(RK)", shape=Msquare];
+ inter_222926448_OUT1 -> node_219342608 [headlabel="k", arrowhead="normal", arrowtail="none", dir=both];
+ inter_220133104_time -> node_219342608 [headlabel="time", arrowhead="normal", arrowtail="none", dir=both];
+ inter_220133104_rel_time -> node_219342608 [headlabel="rel_time", arrowhead="normal", arrowtail="none", dir=both];
+ inter_220133104_delta -> node_219342608 [headlabel="h", arrowhead="normal", arrowtail="none", dir=both];
+ inter_219556304_OUT1 -> node_219342608 [headlabel="IC1", arrowhead="normal", arrowtail="none", dir=both];
+ inter_222606864_OUT1 -> node_219342608 [headlabel="IC2", arrowhead="normal", arrowtail="none", dir=both];
+ inter_219342608_OUT1 [shape=point, width=0.01, height=0.01];
+ node_219342608 -> inter_219342608_OUT1 [taillabel="OUT1", arrowtail="invempty", arrowhead="none", dir=both];
+ inter_219342608_OUT2 [shape=point, width=0.01, height=0.01];
+ node_219342608 -> inter_219342608_OUT2 [taillabel="OUT2", arrowtail="invempty", arrowhead="none", dir=both];
+ inter_219342608_h_new [shape=point, width=0.01, height=0.01];
+ node_219342608 -> inter_219342608_h_new [taillabel="h_new", arrowtail="invempty", arrowhead="none", dir=both];
+ node_220133104 [label="Clock\n(clock)", shape=Msquare];
+ inter_219341456_OUT1 -> node_220133104 [headlabel="h", arrowhead="normal", arrowtail="none", dir=both];
+ inter_220133104_time [shape=point, width=0.01, height=0.01];
+ node_220133104 -> inter_220133104_time [taillabel="time", arrowtail="invempty", arrowhead="none", dir=both];
+ inter_220133104_rel_time [shape=point, width=0.01, height=0.01];
+ node_220133104 -> inter_220133104_rel_time [taillabel="rel_time", arrowtail="invempty", arrowhead="none", dir=both];
+ inter_220133104_delta [shape=point, width=0.01, height=0.01];
+ node_220133104 -> inter_220133104_delta [taillabel="delta", arrowtail="invempty", arrowhead="none", dir=both];
+ node_221342480 [label=" ConstantBlock\n(HIC)\n0.1", shape=ellipse];
+ inter_221342480_OUT1 [shape=point, width=0.01, height=0.01];
+ node_221342480 -> inter_221342480_OUT1 [taillabel="OUT1", arrowtail="invempty", arrowhead="none", dir=both];
+ node_222123920 [label="DelayBlock\n(HDelay)", shape=box];
+ inter_219342608_h_new -> node_222123920 [headlabel="IN1", arrowhead="normal", arrowtail="none", dir=both];
+ inter_221342480_OUT1 -> node_222123920 [headlabel="IC", arrowhead="normal", arrowtail="none", dir=both];
+ inter_222123920_OUT1 [shape=point, width=0.01, height=0.01];
+ node_222123920 -> inter_222123920_OUT1 [taillabel="OUT1", arrowtail="invempty", arrowhead="none", dir=both];
+ node_222606864 [label=" ConstantBlock\n(x0)\n0.0", shape=ellipse];
+ inter_222606864_OUT1 [shape=point, width=0.01, height=0.01];
+ node_222606864 -> inter_222606864_OUT1 [taillabel="OUT1", arrowtail="invempty", arrowhead="none", dir=both];
+ node_219556304 [label=" ConstantBlock\n(v0)\n0.0", shape=ellipse];
+ inter_219556304_OUT1 [shape=point, width=0.01, height=0.01];
+ node_219556304 -> inter_219556304_OUT1 [taillabel="OUT1", arrowtail="invempty", arrowhead="none", dir=both];
+ node_222926448 [label=" ConstantBlock\n(k)\n0.03", shape=ellipse];
+ inter_222926448_OUT1 [shape=point, width=0.01, height=0.01];
+ node_222926448 -> inter_222926448_OUT1 [taillabel="OUT1", arrowtail="invempty", arrowhead="none", dir=both];
+ node_219344304 [label=" ConstantBlock\n(H)\ninf", shape=ellipse];
+ inter_219344304_OUT1 [shape=point, width=0.01, height=0.01];
+ node_219344304 -> inter_219344304_OUT1 [taillabel="OUT1", arrowtail="invempty", arrowhead="none", dir=both];
+ node_219341456 [label="MinBlock\n(Min)", shape=box];
+ inter_219344304_OUT1 -> node_219341456 [headlabel="IN1", arrowhead="normal", arrowtail="none", dir=both];
+ inter_222123920_OUT1 -> node_219341456 [headlabel="IN2", arrowhead="normal", arrowtail="none", dir=both];
+ inter_219341456_OUT1 [shape=point, width=0.01, height=0.01];
+ node_219341456 -> inter_219341456_OUT1 [taillabel="OUT1", arrowtail="invempty", arrowhead="none", dir=both];
 
 }

+ 2 - 2
src/CBD/Core.py

@@ -584,8 +584,8 @@ class CBD(BaseBlock):
         :code:`to_block` with :code:`outport_port_name`.
 
         Args:
-            from_block (BaseBlock): The block to start the connection from.
-            to_block (BaseBlock):   The target block of the connection.
+            from_block (str):       The block to start the connection from.
+            to_block (str):         The target block of the connection.
             input_port_name (str):  The name of the input port. When :code:`None` or unset,
                                     the next port is used. E.g. when called after :code:`IN1`
                                     is already set, :code:`IN2` will be used.

+ 89 - 79
src/CBD/converters/latexify/CBD2Latex.py

@@ -1,4 +1,6 @@
-from CBD.converters.latexify.functions import Fnc, Eq, _BLOCK_MAP, ConstantFnc
+from CBD.converters.latexify.functions import *
+from CBD.converters.latexify.functions import _BLOCK_MAP
+
 
 # TODO: test eq generation, printing and simplifications
 class CBD2Latex:
@@ -74,7 +76,7 @@ class CBD2Latex:
 			if k in self.config:
 				self.config[k] = kwargs[k]
 
-		self.equations = {}
+		self.equations = []
 		self.outputs = [self._rename(self.model.getPath(self.config['path_sep']) + self.config['path_sep'] + x) for x in self.model.getSignals().keys()]
 		assert len(self.outputs) > 0, "Cannot create latex representation without outputs."
 		self._collect_equations()
@@ -105,7 +107,7 @@ class CBD2Latex:
 		bdata = _BLOCK_MAP.get(block.getBlockType(), lambda b: [Fnc(b.getFunctionName())])
 		fncs = bdata(block)
 		for f in fncs:
-			f.args = inputs[:]
+			f.args = [VarFnc(x) for x in inputs]
 		eqs = []
 		outputs = [block.getPath(self.config["path_sep"]) + self.config['path_sep'] + x for x in block.getSignals().keys()]
 		for i, fnc in enumerate(fncs):
@@ -125,21 +127,21 @@ class CBD2Latex:
 			if block.getBlockType() not in ["OutputPortBlock", "InputPortBlock", "WireBlock"]:
 				eq = self.get_block_equation(block)
 				for e in eq:
-					self.equations[e.lhs] = e
+					self.equations.append(e)
 
 		# Add all connections
 		for block in self.model.getBlocks():
-			# tp = block.getBlockType()
+			tp = block.getBlockType()
 			path = block.getPath(self.config['path_sep'])
 			for k, v in block.getLinksIn().items():
-				# if tp == "OutputPortBlock":
-				# 	lhs = self._rename(path)
-				# 	rhs = ConstantFnc("C", self._rename(v.block.getPath(self.config['path_sep']) + self.config['path_sep'] + v.output_port))
-				# 	self.equations[lhs] = Eq(lhs, rhs)
-				# else:
-				lhs = self._rename(path + self.config['path_sep'] + k)
-				rhs = ConstantFnc("C", self._rename(v.block.getPath(self.config['path_sep']) + self.config['path_sep'] + v.output_port))
-				self.equations[lhs] = Eq(lhs, rhs)
+				if tp == "OutputPortBlock":
+					lhs = self._rename(path)
+					rhs = VarFnc(self._rename(v.block.getPath(self.config['path_sep']) + self.config['path_sep'] + v.output_port))
+					self.equations.append(Eq(lhs, rhs))
+				else:
+					lhs = self._rename(path + self.config['path_sep'] + k)
+					rhs = VarFnc(self._rename(v.block.getPath(self.config['path_sep']) + self.config['path_sep'] + v.output_port))
+					self.equations.append(Eq(lhs, rhs))
 
 	def render(self, rl=True):
 		"""
@@ -206,8 +208,9 @@ class CBD2Latex:
 		This allows model simplifications and optimizations.
 		"""
 		res = ""
-		for k, v in self.equations.items():
-			res += "{}\n".format(repr(v))
+		for eq in self.equations:
+			eq.at(Time.now())
+			res += eq.eq() + '\n'
 		return res
 
 	def create_ic(self):
@@ -248,9 +251,7 @@ class CBD2Latex:
 		links = set()
 		numeric = set()
 		for k, v in self.equations.items():
-			if isinstance(v, str):
-				links.add(k)
-			elif isinstance(v, (int, float)):
+			if isinstance(v.rhs, ConstantFnc):
 				numeric.add(k)
 		for k, v in self.equations.items():
 			if isinstance(v, Fnc):
@@ -270,67 +271,75 @@ class CBD2Latex:
 		See Also:
 			:func:`simplify`
 		"""
+		_MEMORY = []
 		outputs = self.outputs
-		for k, e in self.equations.items():
-			if isinstance(e, Fnc) and e.name in _MEMORY:
-				outputs.append(k)
+		# TODO: Delay blocks
+		# for e in self.equations:
+		# 	if isinstance(e, Fnc) and e.name in _MEMORY:
+		# 		outputs.append(k)
 		to_delete = set()
 		for output in outputs:
-			if output not in self.equations: continue
-			v = self.equations[output]
-			if isinstance(v, list):
-				v = v[0]
-				if v not in self.equations: continue
-				self.equations[output] = self.equations[v]
-				to_delete.add(v)
-			elif isinstance(v, str) and v not in self.outputs:
-				self.equations[output] = self.equations[v]
-			elif isinstance(v, Fnc):
-				for k, e in self.equations.items():
-					if k not in outputs and not (isinstance(e, Fnc) and e.name in _MEMORY):
-						v.apply(k, e)
-						to_delete.add(k)
-			for f in self.equations.values():
-				if isinstance(f, Fnc):
-					if v not in outputs:
-						f.apply(v, output)
+			oeq = None
+			for eq in self.equations:
+				if eq.lhs == output:
+					oeq = eq
+					break
+			if oeq is None: continue
+			deps = oeq.get_dependencies()
+			deqs = []
+			for d in deps:
+				for eq in self.equations:
+					if eq.lhs == d.name:
+						deqs.append(eq)
+			for deq in deqs:
+				oeq.apply(deq)
+				to_delete.add(deq.lhs)
+		# TODO: simplify function
 		for output in outputs:
-			deps = self.get_dependencies_for(output)
-			for dep in deps:
-				if dep in to_delete:
-					to_delete.remove(dep)
-		for k, f in self.equations.items():
-			if isinstance(f, Fnc):
-				self.equations[k] = f.simplify(self.config["merge_sums"], self.config["merge_prods"], self.config["merge_negs"])
-		for td in to_delete:
-			del self.equations[td]
-
-	def get_dependencies_for(self, variable, visited=tuple()):
-		"""
-		Tries to obtain all dependencies of a specific variable, to prevent
-		accidental removal. This will be done via a depth-first search.
-
-		Args:
-			variable (str): The variable to get the dependencies for.
-			visited (iter): A collection of all variables that have been
-							checked.
-		"""
-		value = self.equations.get(variable, None)
-		if isinstance(value, Fnc):
-			deps = value.dependencies()
-		else:
-			deps = []
-		i = 0
-		vis = list(visited)
-		while i < len(deps):
-			if deps[i] not in visited:
-				vis.append(deps[i])
-				n_deps = self.get_dependencies_for(deps[i], vis)
-				for dep in n_deps:
-					if dep not in deps:
-						deps.append(dep)
-			i += 1
-		return deps
+			oeq = None
+			for eq in self.equations:
+				if eq.lhs == output:
+					oeq = eq
+					break
+			if oeq is None: continue
+			deps = [x.name for x in oeq.get_dependencies()]
+			for d in to_delete:
+				if d in deps:
+					to_delete.remove(d)
+		idxs = []
+		for d in to_delete:
+			for i, eq in enumerate(self.equations):
+				if eq.lhs == d:
+					idxs.append(i)
+		for i in reversed(sorted(idxs)):
+			self.equations.pop(i)
+
+	# def get_dependencies_for(self, variable, visited=tuple()):
+	# 	"""
+	# 	Tries to obtain all dependencies of a specific variable, to prevent
+	# 	accidental removal. This will be done via a depth-first search.
+	#
+	# 	Args:
+	# 		variable (str): The variable to get the dependencies for.
+	# 		visited (iter): A collection of all variables that have been
+	# 						checked.
+	# 	"""
+	# 	value = self.equations.get(variable, None)
+	# 	if isinstance(value, Fnc):
+	# 		deps = value.dependencies()
+	# 	else:
+	# 		deps = []
+	# 	i = 0
+	# 	vis = list(visited)
+	# 	while i < len(deps):
+	# 		if deps[i] not in visited:
+	# 			vis.append(deps[i])
+	# 			n_deps = self.get_dependencies_for(deps[i], vis)
+	# 			for dep in n_deps:
+	# 				if dep not in deps:
+	# 					deps.append(dep)
+	# 		i += 1
+	# 	return deps
 
 	def simplify(self, steps=-1):
 		"""
@@ -348,18 +357,15 @@ class CBD2Latex:
 		"""
 		if self.config["show_steps"]:
 			self._trace("INITIAL SYSTEM")
-		self.simplify_links()
-		txt = " substituted all connections and constant values"
 		peq = None
 		i = 0
 		while peq != self.equations:
 			if 0 <= steps <= i: break
 			peq = self.equations.copy()
 			if self.config["show_steps"]:
-				self._trace(txt)
+				self._trace("")
 			self.substitute()
 			i += 1
-			txt = ""
 
 	def _trace(self, text=""):
 		"""Traces a step in the solution.
@@ -374,6 +380,7 @@ class CBD2Latex:
 		print(self.render(None))
 		self._step += 1
 
+
 if __name__ == '__main__':
 	from CBD.Core import CBD
 	from CBD.lib.std import AdderBlock, ConstantBlock
@@ -387,3 +394,6 @@ if __name__ == '__main__':
 	c2l = CBD2Latex(model, ignore_path=False)
 
 	print(c2l.eq())
+	c2l.simplify()
+	print(c2l.eq())
+

+ 64 - 3
src/CBD/converters/latexify/functions.py

@@ -4,6 +4,7 @@ New and improved LaTeX-generation module.
 
 from copy import deepcopy
 
+
 class Time:
 	"""
 	Represents the time variable to be used in the equations.
@@ -88,6 +89,25 @@ class Eq:
 			eq_list.append(Eq(self.lhs, rhs, rhs.eq_time))
 		return eq_list
 
+	def get_dependencies(self):
+		if isinstance(self.rhs, VarFnc):
+			return [self.rhs]
+		return self.rhs.get_dependencies()
+
+	def eq(self):
+		return "{lhs}({time}) = {rhs}".format(lhs=self.lhs, time=self.time, rhs=self.rhs.eq())
+
+	def latex(self):
+		return "{lhs}({time}) = {rhs}".format(lhs=self.lhs, time=self.time, rhs=self.rhs.latex())
+
+	def apply(self, other):
+		if isinstance(self.rhs, VarFnc) and self.rhs.name == other.lhs:
+			self.rhs = other.rhs
+		else:
+			for i, a in enumerate(self.rhs.args):
+				if isinstance(a, VarFnc) and a.name == other.lhs:
+					self.rhs.args[i] = other.rhs
+
 
 class Fnc:
 	"""
@@ -133,6 +153,18 @@ class Fnc:
 		"""
 		return "%s(%s)" % (self.name, ", ".join([x.eq() for x in self.args]))
 
+	def get_dependencies(self):
+		"""
+		Recursively obtains the dependencies of the current function.
+		"""
+		res = []
+		for a in self.args:
+			if isinstance(a, VarFnc):
+				res.append(a)
+			else:
+				res += a.get_dependencies()
+		return res
+
 	def at(self, time):
 		"""
 		Computes the function at a specific point in time.
@@ -148,7 +180,10 @@ class Fnc:
 			fncsets.append(arg.at(time))
 		args = self._cross_product_fncs(*fncsets)
 		# TODO: create a list of functions that respect all arguments
-		return args
+		for a in args:
+			k = self.__class__(self.name, self.time, self.eq_time)
+			k.args = a
+			yield k
 
 	@staticmethod
 	def _cross_product_fncs(l1, l2, *lists):
@@ -250,6 +285,32 @@ class ConstantFnc(Fnc):
 	def latex(self):
 		return str(self.val)
 
+	def at(self, time):
+		return [self]
+
+
+class VarFnc(Fnc):
+	"""
+	Function that represents a variable name
+	"""
+	def __init__(self, name, time=Time.now(), eq_time=Time.now()):
+		Fnc.__init__(self, name, time=time, eq_time=eq_time)
+
+	def __str__(self):
+		return str(self.name)
+
+	def eq(self):
+		return "%s(%s)" % (str(self.name), str(self.time))
+
+	def latex(self):
+		return "%s(%s)" % (str(self.name), str(self.time))
+
+	def at(self, time):
+		self.time = time
+		self.eq_time = time
+		return [self]
+
+
 # TODO: der, delay, integrator
 _BLOCK_MAP = {
 	"ConstantBlock": lambda block: [ConstantFnc("C", block.getValue())],
@@ -267,12 +328,12 @@ _BLOCK_MAP = {
 	"NotBlock": lambda block: [UnaryFnc("!", "\\neg")],
 	"OrBlock": lambda block: [BinaryFnc("or", "{a} \\wedge {b}")],
 	"AndBlock": lambda block: [BinaryFnc("and", "{a} \\vee {b}")],
-	"TimeBlock": lambda block: [ConstantFnc("time", "i")],
+	"TimeBlock": lambda block: [VarFnc("time")],
 }
 
 
 if __name__ == '__main__':
-	l1 = [Fnc('+', Fnc('h', time=Time(-1, True)), Fnc('time', time=Time(-1, True))), Fnc('IC1', time=Time(0), eq_time=Time(0))]
+	l1 = [Fnc('+'), Fnc('IC1', time=Time(0), eq_time=Time(0))]
 	l2 = [Fnc('IC2')]
 	l3 = [Fnc('q', time=Time(-1, True)), Fnc('IC3', time=Time(0), eq_time=Time(0))]
 

+ 10 - 9
src/CBD/solver.py

@@ -68,12 +68,12 @@ class LinearSolver(Solver):
 		For a block to comprise the strong component, at least one of its dependencies must be in the strong
 		component as well.
 
-        Args:
-            strongComponent (list): The detected loop, in a list (of BaseBlock instances)
+		Args:
+			strongComponent (list): The detected loop, in a list (of BaseBlock instances)
 
-        Returns:
-            :class:`True` if the loop is linear, else :code:`False`.
-        """
+		Returns:
+			:class:`True` if the loop is linear, else :code:`False`.
+		"""
 		# TO IMPLEMENT
 
 		"""
@@ -91,8 +91,8 @@ class LinearSolver(Solver):
 
 		# WON'T APPEAR: Constant, Sequence, Time, Logging
 		# LINEAR: Negator, Adder, Delay, Input, Output, Wire
-		# NON-LINEAR: Inverter, Modulo, Root, LT, EQ, LTE, Not, Or, And, MUX, Generic, ABS, Int, Power
-		# SEMI-LINEAR: Product
+		# NON-LINEAR: Inverter, Modulo, Root, LT, EQ, LTE, Not, Or, And, MUX, Generic, ABS, Int, Power, Min, Max, Clamp
+		# SEMI-LINEAR: Product // MUX?
 
 		for block in strongComponent:
 			# condition (1)
@@ -103,8 +103,9 @@ class LinearSolver(Solver):
 
 			# condition (2) and (3)
 			if block.getBlockType() in ["InverterBlock", "ModuloBlock", "RootBlock", "LessThanBlock", "EqualsBlock",
-			                            "LessThanOrEqualsBlock", "NotBlock", "OrBlock", "AndBlock",
-			                            "MultiplexerBlock", "GenericBlock", "AbsBlock", "IntBlock", "PowerBlock"]:
+										"LessThanOrEqualsBlock", "NotBlock", "OrBlock", "AndBlock", "MinBlock",
+										"MaxBlock", "MultiplexerBlock", "GenericBlock", "AbsBlock", "IntBlock",
+										"PowerBlock", "ClampBlock"]:
 				return False
 
 		return True