Randy Paredis 4 vuotta sitten
vanhempi
commit
ec8a62a682

+ 2 - 0
.gitignore

@@ -26,3 +26,5 @@ examples/AGV/tuning8/
 examples/AGV/tuning9/
 
 doc/_build/
+/src/CBD.egg-info/
+/src/dist/

+ 2 - 5
doc/install.rst

@@ -58,13 +58,10 @@ There are a few ways of using the framework:
 
    .. code-block:: bash
 
-      # OPTION 1:
+      # BUILDING:
       python setup.py install --user
 
-      # OPTION 2:
-      pip install .
-
-      # OPTION 3:
+      # UPDATING:
       python -m pip install .
 
 Standalone

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 1 - 0
examples/Oscilator/Oscilator.drawio


+ 37 - 0
examples/Oscilator/Oscilator.py

@@ -0,0 +1,37 @@
+#!/usr/bin/python3
+# This file was automatically generated from drawio2cbd with the command:
+#   /home/red/git/DrawioConvert/__main__.py -F CBD -e Oscilator -E delta=0.1 -t 1000 Oscilator.drawio -f
+
+from CBD.Core import *
+from CBD.lib.std import *
+
+DELTA_T = 0.1
+
+class Oscilator(CBD):
+    def __init__(self, block_name):
+        CBD.__init__(self, block_name, input_ports=[], output_ports=['y'])
+
+        # Create the Blocks
+        self.addBlock(TimeBlock("time"))
+        self.addBlock(GenericBlock("sin1", block_operator=("sin")))
+        self.addBlock(GenericBlock("sin2", block_operator=("sin")))
+        self.addBlock(GenericBlock("cos1", block_operator=("cos")))
+        self.addBlock(GenericBlock("cos2", block_operator=("cos")))
+        self.addBlock(ProductBlock("prod1"))
+        self.addBlock(ProductBlock("prod2"))
+        self.addBlock(AdderBlock("sum"))
+
+        # Create the Connections
+        self.addConnection("time", "cos1", output_port_name='OUT1', input_port_name='IN1')
+        self.addConnection("time", "prod1", output_port_name='OUT1', input_port_name='IN2')
+        self.addConnection("time", "sin1", output_port_name='OUT1', input_port_name='IN1')
+        self.addConnection("time", "prod2", output_port_name='OUT1', input_port_name='IN1')
+        self.addConnection("cos1", "prod1", output_port_name='OUT1', input_port_name='IN1')
+        self.addConnection("prod1", "sin2", output_port_name='OUT1', input_port_name='IN1')
+        self.addConnection("sin1", "prod2", output_port_name='OUT1', input_port_name='IN2')
+        self.addConnection("prod2", "cos2", output_port_name='OUT1', input_port_name='IN1')
+        self.addConnection("sin2", "sum", output_port_name='OUT1', input_port_name='IN1')
+        self.addConnection("cos2", "sum", output_port_name='OUT1', input_port_name='IN2')
+        self.addConnection("sum", "y", output_port_name='OUT1')
+
+

+ 22 - 0
examples/Oscilator/Oscilator_experiment.py

@@ -0,0 +1,22 @@
+#!/usr/bin/python3
+# This file was automatically generated from drawio2cbd with the command:
+#   /home/red/git/DrawioConvert/__main__.py -F CBD -e Oscilator -E delta=0.1 -t 1000 Oscilator.drawio -f
+
+from Oscilator import *
+from CBD.simulator import Simulator
+from CBD.converters.CBD2C import CBD2C
+
+DELTA_T = 0.1
+
+cbd = Oscilator("Oscilator")
+
+# Run the Simulation
+# sim = Simulator(cbd)
+# sim.setDeltaT(DELTA_T)
+# sim.run(1000.0)
+
+# print("Y:", cbd.getSignals()["y"][-1])
+
+# TODO: Process Your Simulation Results
+gen = CBD2C(cbd, 10000, 0.1)
+gen.generate("build/oscilator.c")

BIN
examples/Oscilator/build/a.out


+ 142 - 0
examples/Oscilator/build/lsolve.c

@@ -0,0 +1,142 @@
+#include <math.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include "lsolve.h"
+
+double getelm(double* matrix, const unsigned int i, const unsigned int j, const unsigned int m) {
+    const unsigned n = m + 1;
+    return *((matrix + i * n) + j);
+}
+
+void setelm(double* matrix, const unsigned i, const unsigned int j, const unsigned int m, double val) {
+    const unsigned n = m + 1;
+    *((matrix + i * n) + j) = val;
+}
+
+unsigned int argmax_abs(const unsigned int low, const unsigned int high, const unsigned int column, double* A) {
+    unsigned int i_max = 0;
+    double max_value = -1.0;  // computes the abs argmax, so always larger than -1
+    for(unsigned int i = low; i < high; ++i) {
+        double a = fabs(getelm(A, i, column, high));
+        if(a > max_value) {
+            max_value = a;
+            i_max = i;
+        }
+    }
+    return i_max;
+}
+
+void swrows(double* matrix, const unsigned int r1, const unsigned int r2, const unsigned int cols) {
+    if(r1 == r2) { return; }
+    double tmp;
+    for(unsigned int i = 0; i < cols; ++i) {
+        tmp = getelm(matrix, r2, i, cols - 1);
+        setelm(matrix, r2, i, cols - 1, getelm(matrix, r1, i, cols - 1));
+        setelm(matrix, r1, i, cols - 1, tmp);
+    }
+}
+
+void lsolve(double* matrix, const unsigned int size) {
+    const double eps = 1e-4;
+    const unsigned int m = size;        // rows
+    const unsigned int n = size + 1;    // columns
+    unsigned int h = 0;                 // pivot row
+    unsigned int k = 0;                 // pivot column
+
+    while(h < m && k < n) {
+        unsigned int i_max = argmax_abs(h, m, k, matrix);
+        double elm = getelm(matrix, i_max, k, m);
+        if(fabs(elm) <= eps) {
+            // Go to the next column
+            k += 1;
+        } else {
+            swrows(matrix, h, i_max, n);
+            for(unsigned int i = k; i < n; ++i) {
+                setelm(matrix, h, i, m, getelm(matrix, h, i, m) / elm);
+            }
+            for(unsigned int i = 0; i < m; ++i) {
+                if(i == h) { continue; }
+                double f = getelm(matrix, i, k, m) / getelm(matrix, h, k, m);
+                setelm(matrix, i, k, m, 0.0);
+                for(unsigned int j = k + 1; j < n; ++j) {
+                    setelm(matrix, i, j, m, getelm(matrix, i, j, m) - getelm(matrix, h, j, m) * f);
+                }
+            }
+            swrows(matrix, h, i_max, n);
+
+//            printf("MAT %d, %d\n", i_max, k);
+//            for(unsigned int i = 0; i < m; ++i) {
+//                for(unsigned int j = 0; j < n; ++j) {
+//                    printf("\t%7f", getelm(matrix, i, j, m));
+//                }
+//                printf("\n");
+//            }
+
+            h += 1;
+            k += 1;
+        }
+    }
+}
+
+double det(double* matrix, const unsigned int size) {
+    unsigned int height = size - 1;
+
+    if(size == 2) {
+        double a00 = getelm(matrix, 0, 0, size);
+        double a01 = getelm(matrix, 0, 1, size);
+        double a10 = getelm(matrix, 1, 0, size);
+        double a11 = getelm(matrix, 1, 1, size);
+        return (a00 * a11) - (a01 * a10);
+    }
+
+    double total = 0.0;
+    for(unsigned int fc = 0; fc < size; ++fc) {
+        double As[height][height];
+        for(unsigned int r = 0; r < height; ++r) {
+            for(unsigned int c = 0; c < fc; ++c) {
+                As[r][c] = getelm(matrix, r + 1, c, height);
+            }
+            for(unsigned int c = fc; c < height; ++c) {
+                As[r][c] = getelm(matrix, r + 1, c + 1, height);
+            }
+        }
+        double sign = -1.0;
+        if(fc % 2 == 1) {
+            sign = 1.0;
+        }
+        double sub_det = det(&As, height);
+        total += sign * getelm(matrix, 0, fc, height) * sub_det;
+    }
+    return total;
+}
+
+void agloop(double* A, const unsigned int size, ...) {
+    double D = det(A, size);
+    if(fabs(D) < 1e-5) {
+        printf("ERROR: SINGULAR MATRIX!\n");
+        exit(1);
+    }
+    lsolve(A, size);
+
+    // Read the arguments
+    va_list list;
+    va_start(list, size);
+    for(unsigned int j = 0; j < size; ++j) {
+        *va_arg(list, double*) = getelm(A, j, size, size);
+    }
+    va_end(list);
+}
+
+//int main(int argc, char *args[]) {
+//    double A[2][3] = {{-1.0, 6.0, 0.0}, {1.0, -1.0, -3.0}};
+//    lsolve(&A, 2);
+//
+////    printf("END\n");
+////    for(unsigned int i = 0; i < 2; ++i) {
+////        for(unsigned int j = 0; j < 3; ++j) {
+////            printf("\t%7f", A[i][j]);
+////        }
+////        printf("\n");
+////    }
+//}

+ 76 - 0
examples/Oscilator/build/lsolve.h

@@ -0,0 +1,76 @@
+#ifndef LSOLVE
+#define LSOLVE
+
+/**
+ *  Obtains an element from a 2D array matrix, using pointers.
+ *  This is mainly a helper function.
+ *
+ *  @param  matrix  An address to an (NxN+1) matrix, which is
+ *                  to be constructed as a 2D array.
+ *  @param  i       The row index of the element to obtain.
+ *  @param  j       The column index of the element to obtain.
+ *  @param  m       The amount of rows for the input matrix.
+ **/
+double getelm(double* matrix, const unsigned int i, const unsigned int j, const unsigned int m);
+
+/**
+ *  Sets an element in a 2D array matrix, using pointers.
+ *  This is mainly a helper function.
+ *
+ *  @param  matrix  An address to an (NxN+1) matrix, which is
+ *                  to be constructed as a 2D array.
+ *  @param  i       The row index of the element to set.
+ *  @param  j       The column index of the element to set.
+ *  @param  m       The amount of rows for the input matrix.
+ *  @param  val     The new value for the element.
+ **/
+void setelm(double* matrix, const unsigned int i, const unsigned int j, const unsigned int m, double val);
+
+/**
+ *  Computes the row index that yields the highest absolute value.
+ *  This is mainly a helper function.
+ *
+ *  @param  low     The minimal row index to return.
+ *  @param  high    The maximal row index to return.
+ *  @param  A       An address to an (NxN+1) matrix, which is
+ *                  to be constructed as a 2D array.
+ **/
+unsigned int argmax_abs(const unsigned int low, const unsigned int high, const unsigned int column, double* A);
+
+/**
+ *  Solves a system of equations linearly, by using matrices
+ *  and Gauss-Jordan Elimination. Only works for N equations
+ *  and N unknowns.
+ *
+ *  @param  matrix  An address to an (NxN+1) matrix, which is
+ *                  to be constructed as a 2D array.
+ *  @param  size    The amount of rows for the input matrix N.
+ **/
+void lsolve(double* matrix, const unsigned int size);
+
+/**
+ *  Computes the determinant of the matrix.
+ *
+ *  @param  matrix  An address to an (NxN) matrix, which is
+ *                  to be constructed as a 2D array.
+ *  @param  size    The amount of rows for the input matrix N.
+ **/
+double det(double* matrix, const unsigned int size);
+
+/**
+ *  Helper function to linearly solve algebraic loops.
+ *  This first checks if the block matrix is not singular,
+ *  after which it solves the equations w.r.t. Gauss-Jordan.
+ *  Finally, the resulting matrix is automatically stored in
+ *  the corresponding variables.
+ *
+ *  @param  A       An address to an (NxN+1) matrix, which is
+ *                  to be constructed as a 2D array.
+ *  @param  size    The amount of rows for the input matrix N.
+ *  @param  ...     An undefined amount of arguments that refer
+ *                  to the variables in which the data must be
+ *                  stored in the end.
+ **/
+void agloop(double* A, const unsigned int size, ...);
+
+#endif

+ 70 - 0
examples/Oscilator/build/oscilator.c

@@ -0,0 +1,70 @@
+#include <math.h>
+#include <stdio.h>
+#include <time.h>
+#include "lsolve.h"
+
+#define M 10    /* No of Blocks */
+#define N 10000    /* No of Iterations */
+
+/* BLOCK VARIABLE NAMES */
+#define Oscilator_time_OUT1 RESULT[0]
+#define Oscilator_time_relative RESULT[1]
+#define Oscilator_sin1_OUT1 RESULT[2]
+#define Oscilator_sin2_OUT1 RESULT[3]
+#define Oscilator_cos1_OUT1 RESULT[4]
+#define Oscilator_cos2_OUT1 RESULT[5]
+#define Oscilator_prod1_OUT1 RESULT[6]
+#define Oscilator_prod2_OUT1 RESULT[7]
+#define Oscilator_sum_OUT1 RESULT[8]
+#define Oscilator_y RESULT[9]
+
+double RESULT[M][N];
+
+/* EQUATIONS */
+void _eq_init(const double time, const double delta) {
+    Oscilator_time_OUT1[0] = time;
+    Oscilator_sin1_OUT1[0] = sin(Oscilator_time_OUT1[0]);
+    Oscilator_cos1_OUT1[0] = cos(Oscilator_time_OUT1[0]);
+    Oscilator_prod1_OUT1[0] = (Oscilator_cos1_OUT1[0]) * (Oscilator_time_OUT1[0]);
+    Oscilator_sin2_OUT1[0] = sin(Oscilator_prod1_OUT1[0]);
+    Oscilator_prod2_OUT1[0] = (Oscilator_time_OUT1[0]) * (Oscilator_sin1_OUT1[0]);
+    Oscilator_cos2_OUT1[0] = cos(Oscilator_prod2_OUT1[0]);
+    Oscilator_sum_OUT1[0] = (Oscilator_sin2_OUT1[0]) + (Oscilator_cos2_OUT1[0]);
+    Oscilator_y[0] = Oscilator_sum_OUT1[0];
+}
+
+void _eq_iter(const unsigned int i, const double time, const double delta) {
+    Oscilator_time_OUT1[i] = time;
+    Oscilator_sin1_OUT1[i] = sin(Oscilator_time_OUT1[i]);
+    Oscilator_cos1_OUT1[i] = cos(Oscilator_time_OUT1[i]);
+    Oscilator_prod1_OUT1[i] = (Oscilator_cos1_OUT1[i]) * (Oscilator_time_OUT1[i]);
+    Oscilator_sin2_OUT1[i] = sin(Oscilator_prod1_OUT1[i]);
+    Oscilator_prod2_OUT1[i] = (Oscilator_time_OUT1[i]) * (Oscilator_sin1_OUT1[i]);
+    Oscilator_cos2_OUT1[i] = cos(Oscilator_prod2_OUT1[i]);
+    Oscilator_sum_OUT1[i] = (Oscilator_sin2_OUT1[i]) + (Oscilator_cos2_OUT1[i]);
+    Oscilator_y[i] = Oscilator_sum_OUT1[i];
+}
+
+/* SIMULATOR */
+int main(int argc, char *args[]) {
+    double delta = 0.1;
+    double time = 0.0;
+
+    _eq_init(0.0, delta);
+    for(int i = 1; i < N; ++i) {
+        time += delta;
+        _eq_iter(i, time, delta);
+    }
+
+    printf("\t%-20s = %12.4f\n", "TIME", time);
+    printf("\t%-20s = %12.4f\n", "Oscilator_time_OUT1", Oscilator_time_OUT1[N - 1]);
+    printf("\t%-20s = %12.4f\n", "Oscilator_time_relative", Oscilator_time_relative[N - 1]);
+    printf("\t%-20s = %12.4f\n", "Oscilator_sin1_OUT1", Oscilator_sin1_OUT1[N - 1]);
+    printf("\t%-20s = %12.4f\n", "Oscilator_sin2_OUT1", Oscilator_sin2_OUT1[N - 1]);
+    printf("\t%-20s = %12.4f\n", "Oscilator_cos1_OUT1", Oscilator_cos1_OUT1[N - 1]);
+    printf("\t%-20s = %12.4f\n", "Oscilator_cos2_OUT1", Oscilator_cos2_OUT1[N - 1]);
+    printf("\t%-20s = %12.4f\n", "Oscilator_prod1_OUT1", Oscilator_prod1_OUT1[N - 1]);
+    printf("\t%-20s = %12.4f\n", "Oscilator_prod2_OUT1", Oscilator_prod2_OUT1[N - 1]);
+    printf("\t%-20s = %12.4f\n", "Oscilator_sum_OUT1", Oscilator_sum_OUT1[N - 1]);
+    printf("\t%-20s = %12.4f\n", "Oscilator_y", Oscilator_y[N - 1]);
+}

+ 6 - 0
examples/Oscilator/build/run.sh

@@ -0,0 +1,6 @@
+
+for i in {0..1000}
+do
+  echo "LOOP $i"
+  ./a.out
+done

+ 35 - 0
examples/Oscilator/info.txt

@@ -0,0 +1,35 @@
+1000 executions
+0.1 delta
+1000 time
+No algebraic loop
+
+C generation:
+    real	0m0.421s
+    user	0m0.385s
+    sys	    0m0.036s
+
+C compilation:
+    real	0m0.125s
+    user	0m0.097s
+    sys	    0m0.028s
+
+Using C code:
+    real	0m1.979s
+    user	0m1.629s
+    sys	    0m0.407s
+
+C Total:
+    real	0m2.525s
+    user	0m2.111s
+    sys	    0m0.471s
+
+Using Python:
+    real	31m36.607s
+    user	30m22.538s
+    sys	    0m46.881s
+
+
+C Optimization (Python / C):
+    real    751.1314
+    user    863.3529
+    sys     99.5350

+ 6 - 0
examples/Oscilator/run.sh

@@ -0,0 +1,6 @@
+
+for i in {0..1000}
+do
+  echo "LOOP $i"
+  python3 Oscilator_experiment.py
+done

+ 91 - 5
src/CBD/converters/CBD2C/__init__.py

@@ -1,5 +1,20 @@
 """
 A module that allows the creation of a C file, in which the block's computations are inlined.
+Additional library files will be created to allow for linking:
+	- lsolve.c
+	- lsolve.h
+
+The :code:`template.c` file is the jinja template file.
+
+Note:
+	To compile the generated code, execute
+
+	```
+		gcc <filename>.c lsolve.c -lm
+	```
+
+Requires:
+	- `Jinja2 <https://jinja.palletsprojects.com/en/3.0.x/>`_
 """
 from CBD.scheduling import TopologicalScheduler
 from CBD.solver import GaussianJordanLinearSolver
@@ -8,11 +23,34 @@ from CBD.converters.latexify import CBD2Latex, _BLOCK_MAP
 import CBD.naivelog as naivelog
 
 from jinja2 import Template
+from shutil import copyfile
+import os
 
 class CBD2C:
+	"""
+	Main conversion class. Generates the new C file.
+	The C model will be executed in fixed-time steps of size
+	:code:`delta`, for a total of :code:`itcnt` iterations.
+	In total, the simulation will thus execute until timestep
+	:code:`itcnt * delta`.
+
+	Note:
+		This class does *not* change the original model.
+
+	Warning:
+		This class only works if the dependency graph is fixed
+		after the first iteration. I.e., iteration 0 can be
+		different, but all others must be the same.
+
+	Args:
+		model (CBD):    CBD model that will be converted to C.
+		itcnt (int):    The amount of iterations to execute the
+						c model for.
+		delta (float):  The stepsize of the C code.
+	"""
 	def __init__(self, model, itcnt, delta=1.0):
 		self.itcnt = itcnt
-		self.delta = 1.0
+		self.delta = delta
 		self.model = model.clone()
 		self.model.flatten(psep='_')
 		for block in self.model.getBlocks():
@@ -21,17 +59,48 @@ class CBD2C:
 		self.solver = GaussianJordanLinearSolver(naivelog.getLogger("CBD"))
 
 	def get_blocks(self):
+		"""
+		Gets all the blocks from the flattened model.
+		"""
 		return self.model.getBlocks()
 
 	def get_order(self, curIt):
+		"""
+		Gets the topological order of the blocks at a specific iteration.
+
+		Args:
+			curIt (int):
+		"""
 		depGraph = createDepGraph(self.model, curIt)
 		return self.scheduler.schedule(depGraph, curIt, 0.0)
 
 	@staticmethod
 	def flatten(t):
+		"""
+		Flattens a list of sublists.
+
+		Args:
+			t (iter):   The list to flatten.
+		"""
 		return [item for sublist in t for item in sublist]
 
 	def obtain_data_from_order(self, order, curIt):
+		"""
+		Given the order in which the blocks must be executed,
+		this function will use the :class:`CBD2Latex` class to
+		construct the C-representation for the functions.
+
+		Args:
+			order:          List of components, topologically ordered.
+			curIt (int):    The current iteration.
+
+		Returns:
+			A list of tuples like :code:`[([LHS, ...], RHS), ...]`;
+			where the :code:`LHS` identifies an ordered list of
+			left-hand sides (when there are multiple, it means an
+			algebraic loop); and :code:`RHS` the string-representation
+			of the results.
+		"""
 		i = "0" if curIt == 0 else "i"
 		conf = {"path_sep": '_', "ignore_path": False, "escape_nonlatex": False, "time_variable": "time"}
 		norder = []
@@ -48,6 +117,8 @@ class CBD2C:
 					kv = {x: n.getBlockConnectedToInput(x) for x in n.getInputPortNames()}
 					for k, v in kv.items():
 						bd[1].apply(n.getPath('_') + '_' + k, v.block.getPath('_') + '_' + v.output_port)
+					# if not isinstance(bd[1], str):
+					# 	bd[1].args = ["(double)%s" % str(x) for x in bd[1].args]
 					if n.getBlockType() == "DelayBlock":
 						if curIt == 0:
 							bd[1].apply_time(time=-1, t=i, fmt="[{time}]")
@@ -90,12 +161,29 @@ class CBD2C:
 
 					nc = (dlist, str(mat).replace("[", "{").replace("]", "}"))
 			norder.append(nc)
-		print(norder)
 		return norder
 
 	def generate(self, fname):
-		with open("template.c", 'r') as file:
+		"""
+		Generates the C file and copies the sources for the
+		lsolve library in the same folder.
+
+		To compile the generated code, execute
+
+		```
+			gcc <filename>.c lsolve.c -lm
+		```
+
+		Args:
+			fname (str):    The filename of the C-code.
+		"""
+		path = os.path.dirname(os.path.realpath(__file__))
+		tpath = os.path.dirname(os.path.realpath(fname))
+		filename = os.path.join(path, "template.c")
+		with open(filename, 'r') as file:
 			template = Template(file.read(), trim_blocks=True, lstrip_blocks=True)
+		copyfile(os.path.join(path, "lsolve.c"), os.path.join(tpath, "lsolve.c"))
+		copyfile(os.path.join(path, "lsolve.h"), os.path.join(tpath, "lsolve.h"))
 		variables = []
 		for block in self.get_blocks():
 			if block.getBlockType() == "WireBlock":
@@ -111,8 +199,6 @@ class CBD2C:
 		comp0 = self.obtain_data_from_order(comp0, 0)
 		comp = self.obtain_data_from_order(comp, 1)
 
-		# print(comp0)
-
 		contents = template.render(itcnt = self.itcnt,
 		                           delta = self.delta,
 		                           variables = variables,

BIN
src/CBD/converters/CBD2C/a.out


+ 0 - 62
src/CBD/converters/CBD2C/code.c

@@ -1,62 +0,0 @@
-#include <math.h>
-#include <stdio.h>
-#include <time.h>
-#include "lsolve.h"
-
-#define M 8    /* No of Blocks */
-#define N 100    /* No of Iterations */
-
-/* BLOCK VARIABLE NAMES */
-#define Factorial_GSTB9gRuDpQ50gPdog42_3_OUT1 RESULT[0]
-#define Factorial_GSTB9gRuDpQ50gPdog42_7_OUT1 RESULT[1]
-#define Factorial_GSTB9gRuDpQ50gPdog42_12_OUT1 RESULT[2]
-#define Factorial_GSTB9gRuDpQ50gPdog42_12_relative RESULT[3]
-#define Factorial_one_OUT1 RESULT[4]
-#define Factorial_GSTB9gRuDpQ50gPdog42_24_OUT1 RESULT[5]
-#define Factorial_GSTB9gRuDpQ50gPdog42_31_OUT1 RESULT[6]
-#define Factorial_y RESULT[7]
-
-double RESULT[M][N];
-
-/* EQUATIONS */
-void _eq_init(const double time, const double delta) {
-    Factorial_one_OUT1[0] = 1;
-    Factorial_GSTB9gRuDpQ50gPdog42_3_OUT1[0] = Factorial_one_OUT1[0];
-    Factorial_GSTB9gRuDpQ50gPdog42_24_OUT1[0] = Factorial_one_OUT1[0];
-    Factorial_GSTB9gRuDpQ50gPdog42_7_OUT1[0] = (Factorial_GSTB9gRuDpQ50gPdog42_3_OUT1[0]) * (Factorial_GSTB9gRuDpQ50gPdog42_24_OUT1[0]);
-    Factorial_GSTB9gRuDpQ50gPdog42_12_OUT1[0] = time;
-    Factorial_GSTB9gRuDpQ50gPdog42_31_OUT1[0] = (Factorial_one_OUT1[0]) + (Factorial_GSTB9gRuDpQ50gPdog42_12_OUT1[0]);
-    Factorial_y[0] = Factorial_GSTB9gRuDpQ50gPdog42_7_OUT1[0];
-}
-
-void _eq_iter(const unsigned int i, const double time, const double delta) {
-    Factorial_GSTB9gRuDpQ50gPdog42_3_OUT1[i] = Factorial_GSTB9gRuDpQ50gPdog42_7_OUT1[i-1];
-    Factorial_GSTB9gRuDpQ50gPdog42_24_OUT1[i] = Factorial_GSTB9gRuDpQ50gPdog42_31_OUT1[i-1];
-    Factorial_GSTB9gRuDpQ50gPdog42_7_OUT1[i] = (Factorial_GSTB9gRuDpQ50gPdog42_3_OUT1[i]) * (Factorial_GSTB9gRuDpQ50gPdog42_24_OUT1[i]);
-    Factorial_GSTB9gRuDpQ50gPdog42_12_OUT1[i] = time;
-    Factorial_one_OUT1[i] = 1;
-    Factorial_GSTB9gRuDpQ50gPdog42_31_OUT1[i] = (Factorial_one_OUT1[i]) + (Factorial_GSTB9gRuDpQ50gPdog42_12_OUT1[i]);
-    Factorial_y[i] = Factorial_GSTB9gRuDpQ50gPdog42_7_OUT1[i];
-}
-
-/* SIMULATOR */
-int main(int argc, char *args[]) {
-    double delta = 1.0;
-    double time = 0.0;
-
-    _eq_init(0.0, delta);
-    for(int i = 1; i < N; ++i) {
-        time += delta;
-        _eq_iter(i, time, delta);
-    }
-
-    printf("\t%-20s = %12.4f\n", "TIME", time);
-    printf("\t%-20s = %12.4f\n", "Factorial_GSTB9gRuDpQ50gPdog42_3_OUT1", Factorial_GSTB9gRuDpQ50gPdog42_3_OUT1[N - 1]);
-    printf("\t%-20s = %12.4f\n", "Factorial_GSTB9gRuDpQ50gPdog42_7_OUT1", Factorial_GSTB9gRuDpQ50gPdog42_7_OUT1[N - 1]);
-    printf("\t%-20s = %12.4f\n", "Factorial_GSTB9gRuDpQ50gPdog42_12_OUT1", Factorial_GSTB9gRuDpQ50gPdog42_12_OUT1[N - 1]);
-    printf("\t%-20s = %12.4f\n", "Factorial_GSTB9gRuDpQ50gPdog42_12_relative", Factorial_GSTB9gRuDpQ50gPdog42_12_relative[N - 1]);
-    printf("\t%-20s = %12.4f\n", "Factorial_one_OUT1", Factorial_one_OUT1[N - 1]);
-    printf("\t%-20s = %12.4f\n", "Factorial_GSTB9gRuDpQ50gPdog42_24_OUT1", Factorial_GSTB9gRuDpQ50gPdog42_24_OUT1[N - 1]);
-    printf("\t%-20s = %12.4f\n", "Factorial_GSTB9gRuDpQ50gPdog42_31_OUT1", Factorial_GSTB9gRuDpQ50gPdog42_31_OUT1[N - 1]);
-    printf("\t%-20s = %12.4f\n", "Factorial_y", Factorial_y[N - 1]);
-}

+ 0 - 48
src/CBD/converters/CBD2C/example.c

@@ -1,48 +0,0 @@
-#include <math.h>
-#include <stdio.h>
-#include <time.h>
-#include "lsolve.h"
-
-#define M 4    /* No of Blocks */
-#define N 3000    /* No of Iterations */
-
-/* BLOCK VARIABLE NAMES */
-#define test_A_OUT1 RESULT[0]
-#define test_C_OUT1 RESULT[1]
-#define test_D_OUT1 RESULT[2]
-#define test_x RESULT[3]
-
-double RESULT[M][N];
-
-/* EQUATIONS */
-void _eq_init(const double time, const double delta) {
-    test_C_OUT1[0] = 3.0;
-    test_D_OUT1[0] = 6.0;
-    test_A_OUT1[0] = (test_C_OUT1[0]) + (test_D_OUT1[0]);
-    test_x[0] = test_A_OUT1[0];
-}
-
-void _eq_iter(const unsigned int i, const double time, const double delta) {
-    test_C_OUT1[i] = 3.0;
-    test_D_OUT1[i] = 6.0;
-    test_A_OUT1[i] = (test_C_OUT1[i]) + (test_D_OUT1[i]);
-    test_x[i] = test_A_OUT1[i];
-}
-
-/* SIMULATOR */
-int main(int argc, char *args[]) {
-    double delta = 0.1;
-    double time = 0.0;
-
-    _eq_init(0.0, delta);
-    for(int i = 1; i < N; ++i) {
-        time += delta;
-        _eq_iter(i, time, delta);
-    }
-
-    printf("\t%-20s = %12.4f\n", "TIME", time);
-    printf("\t%-20s = %12.4f\n", "test_A_OUT1", test_A_OUT1[N - 1]);
-    printf("\t%-20s = %12.4f\n", "test_C_OUT1", test_C_OUT1[N - 1]);
-    printf("\t%-20s = %12.4f\n", "test_D_OUT1", test_D_OUT1[N - 1]);
-    printf("\t%-20s = %12.4f\n", "test_x", test_x[N - 1]);
-}

+ 0 - 32
src/CBD/converters/CBD2C/factorial.py

@@ -1,32 +0,0 @@
-#!/usr/bin/python3
-# This file was automatically generated from drawio2cbd with the command:
-#   C:\Users\randy\Documents\MoSIS\assignments\2021\A3-CBD\DrawioConvert.exe -F CBD -e Factorial -sSrgv factorial.drawio
-
-from CBD.Core import *
-from CBD.lib.std import *
-
-
-class Factorial(CBD):
-    def __init__(self, block_name):
-        super().__init__(block_name, input_ports=[], output_ports=['y'])
-
-        # Create the Blocks
-        self.addBlock(DelayBlock("GSTB9gRuDpQ50gPdog42-3"))
-        self.addBlock(ProductBlock("GSTB9gRuDpQ50gPdog42-7"))
-        self.addBlock(TimeBlock("GSTB9gRuDpQ50gPdog42-12"))
-        self.addBlock(ConstantBlock("one", value=(1)))
-        self.addBlock(DelayBlock("GSTB9gRuDpQ50gPdog42-24"))
-        self.addBlock(AdderBlock("GSTB9gRuDpQ50gPdog42-31"))
-
-        # Create the Connections
-        self.addConnection("GSTB9gRuDpQ50gPdog42-3", "GSTB9gRuDpQ50gPdog42-7", output_port_name='OUT1', input_port_name='IN1')
-        self.addConnection("GSTB9gRuDpQ50gPdog42-7", "GSTB9gRuDpQ50gPdog42-3", output_port_name='OUT1', input_port_name='IN1')
-        self.addConnection("GSTB9gRuDpQ50gPdog42-7", "y", output_port_name='OUT1')
-        self.addConnection("one", "GSTB9gRuDpQ50gPdog42-3", output_port_name='OUT1', input_port_name='IC')
-        self.addConnection("one", "GSTB9gRuDpQ50gPdog42-24", output_port_name='OUT1', input_port_name='IC')
-        self.addConnection("one", "GSTB9gRuDpQ50gPdog42-31", output_port_name='OUT1', input_port_name='IN1')
-        self.addConnection("GSTB9gRuDpQ50gPdog42-24", "GSTB9gRuDpQ50gPdog42-7", output_port_name='OUT1', input_port_name='IN2')
-        self.addConnection("GSTB9gRuDpQ50gPdog42-31", "GSTB9gRuDpQ50gPdog42-24", output_port_name='OUT1', input_port_name='IN1')
-        self.addConnection("GSTB9gRuDpQ50gPdog42-12", "GSTB9gRuDpQ50gPdog42-31", output_port_name='OUT1', input_port_name='IN2')
-
-

+ 0 - 23
src/CBD/converters/CBD2C/factorial_experiment.py

@@ -1,23 +0,0 @@
-#!/usr/bin/python3
-# This file was automatically generated from drawio2cbd with the command:
-#   C:\Users\randy\Documents\MoSIS\assignments\2021\A3-CBD\DrawioConvert.exe -F CBD -e Factorial -sSrgv factorial.drawio
-
-from factorial import *
-from CBD.simulator import Simulator
-
-
-cbd = Factorial("Factorial")
-
-# Run the Simulation
-# sim = Simulator(cbd)
-# sim.run(10)
-#
-# for s in cbd.getSignal("y"):
-#    print(s)
-
-# TODO: Process Your Simulation Results
-from CBD.converters.eq2CBD import eq2CBD
-from CBD.converters.CBD2C import CBD2C
-
-gen = CBD2C(cbd, 100, 1.0)
-gen.generate("code.c")

+ 0 - 55
src/CBD/converters/CBD2C/generated.c

@@ -1,55 +0,0 @@
-#include <math.h>
-#include <stdio.h>
-#include <time.h>
-#include <stdlib.h>
-#include "lsolve.h"
-
-#define M 5        /* No of Blocks */
-#define N 300      /* No of Iterations */
-
-/* BLOCK VARIABLE NAMES */
-#define bla_A RESULT[0]
-#define bla_B RESULT[1]
-#define bla_C RESULT[2]
-#define bla_D RESULT[3]
-#define bla_x RESULT[4]
-
-double RESULT[M][N];
-
-/* EQUATIONS */
-void _eq_init(const double time, const double delta) {
-    bla_C[0] = 3.0;
-    bla_D[0] = 6.0;
-
-    /* Algebraic Loop */
-    double _C3[2][3] = {{-1.0, 6.0, 0.0}, {1.0, -1.0, -3.0}};
-    agloop(&_C3, 2, &bla_B[0], &bla_A[0]);
-
-    bla_x[0] = bla_B[0];
-}
-
-void _eq_iter(const unsigned int i, const double time, const double delta) {
-    bla_C[i] = 3.0;
-    bla_D[i] = 6.0;
-
-    /* Algebraic Loop */
-    double _C3[2][3] = {{-1.0, 6.0, 0.0}, {1.0, -1.0, -3.0}};
-    agloop(&_C3, 2, &bla_B[i], &bla_A[i]);
-
-    bla_x[i] = bla_B[i];
-}
-
-/* SIMULATOR */
-int main(int argc, char *args[]) {
-    double delta = 0.1;
-    double time = 0.0;
-
-    _eq_init(delta);
-    for(int i = 1; i < N; ++i) {
-        time += delta;
-        _eq_iter(i, time, delta);
-    }
-
-    printf("\tTIME = %12.4f s\n", time);
-    printf("\tX    = %12.4f\n", bla_x[N - 1]);
-}

+ 0 - 1
src/CBD/converters/__init__.py

@@ -3,4 +3,3 @@ This package contains a set of independent modules pertaining the conversion
 to and from CBDs.
 """
 
-

+ 6 - 3
src/setup.py

@@ -1,4 +1,4 @@
-from distutils.core import setup
+from setuptools import setup, find_packages
 
 setup(name="CBD",
       version="0.1.0",
@@ -11,5 +11,8 @@ setup(name="CBD",
 	      "Randy Paredis <Randy.Paredis@uantwerpen.be>"
       ]),
       url="http://msdl.cs.mcgill.ca/people/rparedis",
-      packages=['CBD', 'CBD.lib', 'CBD.realtime', 'CBD.tracers', 'CBD.preprocessing', 'CBD.converters']
-      )
+      packages=find_packages(include=('CBD.*',)),
+      package_data={
+	      '': ['*.c', '*.h', '*.lark']
+      },
+)