From de7a33c18eadc5828759fdb5b4561f9cd1dfbe65 Mon Sep 17 00:00:00 2001
From: KeSellers <108118397+KeSellers@users.noreply.github.com>
Date: Tue, 24 Jan 2023 17:06:07 +0100
Subject: [PATCH] Klasse zum Simulieren

---
 .vscode/launch.json | 16 +++++++++++
 API.py              | 67 +++++++++++++++++++++++++++++++++++++++------
 Simulation_API.py   | 18 ++++++++++++
 generate_data.py    | 20 ++++++++++++++
 4 files changed, 112 insertions(+), 9 deletions(-)
 create mode 100644 .vscode/launch.json
 create mode 100644 Simulation_API.py
 create mode 100644 generate_data.py

diff --git a/.vscode/launch.json b/.vscode/launch.json
new file mode 100644
index 0000000..306f58e
--- /dev/null
+++ b/.vscode/launch.json
@@ -0,0 +1,16 @@
+{
+    // Use IntelliSense to learn about possible attributes.
+    // Hover to view descriptions of existing attributes.
+    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
+    "version": "0.2.0",
+    "configurations": [
+        {
+            "name": "Python: Current File",
+            "type": "python",
+            "request": "launch",
+            "program": "${file}",
+            "console": "integratedTerminal",
+            "justMyCode": true
+        }
+    ]
+}
\ No newline at end of file
diff --git a/API.py b/API.py
index 2b4b522..eab6117 100644
--- a/API.py
+++ b/API.py
@@ -1,14 +1,52 @@
-from plantsim.plantsim import Plantsim
+from Simulation_API import PlantSimulationAPI
 from plantsim.table import Table
-import networkx as nx
-from DataBase import Lager,Einzelstation,Quelle,Puffer
-from api_utils import build_model_edges, build_model_nodes
-from graph_utils import draw_edges,draw_graph,draw_nodes
+from plantsim.pandas_table import PandasTable
+
+
+
+#from api_utils import build_model_edges, build_model_nodes
+#from graph_utils import draw_edges,draw_graph,draw_nodes
+
+#plantsim = Plantsim(version='', license_type='Student',visible=True,trust_models=True)
+#plantsim.load_model("C:\\Users\\selle\\Desktop\\Masterarbeit\\001_Plant_simulation\\Simulation.spp")
+#plantsim.set_path_context(".Models.Fliess")
+#plantsim.execute_simtalk("&Method.execute()")
+
+model = PlantSimulationAPI(version='', license_type='Student',visible=False,trust_models=True)
+
+model.load_model("C:\\Users\\selle\\Desktop\\Masterarbeit\\001_Plant_simulation\\Simulation.spp")
+
+model.set_path_context(".Models.Fliessprinzip")
+
+#model.run_simulation(1)
+headers =["Durchlaufzeit","Losgroesse1","Losgroesse2","Losgroesse3","AbstandQuelle","ZeitMaschine1","ZeitMaschine2"]
+#test = Table(model,"Ergebnisse",headers)
+#test = PandasTable(model,"Ergebnisse")#(zugriff auf comuputer verbieten ausstellen)print(test)
+#print(test.table)
+
+    
+
+
+
+
+
+
+
+
+
+
+
+
+
+#change_attr(plantsim,"Fraesmaschine1","Bearbeitungszeit", 10)
+#change_attr(plantsim,"Fraesmaschine","Bearbeitungszeit", 10)
+#change_attr(plantsim,"Fraesmaschine","Bearbeitungszeit", 10)
+#change_attr(plantsim,"Fraesmaschine","Bearbeitungszeit", 10)
+
+
+
+
 
-plantsim = Plantsim(version='', license_type='Student',visible=False)
-plantsim.load_model("C:\\Users\\selle\\Desktop\\Masterarbeit\\001_Plant_simulation\\Simulation.spp")
-plantsim.set_path_context(".Models.Lager")
-plantsim.get_value()
 
 #Lager_nodes = build_model_nodes(Lager,plantsim)
 #Lager_edges = build_model_edges(Lager,Lager_nodes)
@@ -21,3 +59,14 @@ plantsim.get_value()
 #Lager_graph = draw_edges(Lager_graph,Lager_edges)
 #draw_graph(Lager_graph)
 
+#def change_attr (sim,name,attr,val):
+#    node = sim.set_value(name + "."+attr,val) 
+#def set_losgroesse(sim,val1,val2,val3):
+#    sim.execute_simtalk("&Method.execute(f'{val1}')")
+
+#change_attr(plantsim,"Fraesmaschine","Bearbeitungszeit", 10)
+#change_attr(plantsim,"QuelleLager","Abstand", 10)
+#print(plantsim.is_simulation_running())
+#set_losgroesse(plantsim,2,17,14)
+#print(plantsim.execute_simtalk("variiereLosgroessen()",[10,14,17]))
+#print(plantsim.get_value("Ergebnisse"))
\ No newline at end of file
diff --git a/Simulation_API.py b/Simulation_API.py
new file mode 100644
index 0000000..5b5cd10
--- /dev/null
+++ b/Simulation_API.py
@@ -0,0 +1,18 @@
+import time
+from plantsim.plantsim import Plantsim
+
+
+class PlantSimulationAPI(Plantsim):
+    def __init__(self, version='', visible=True, trust_models=False, license_type='Student'):
+        super().__init__(version, visible, trust_models, license_type)
+        self.head = None
+
+
+
+
+    def run_simulation(self,n_samples = 1000):
+        
+        for i in range(n_samples):
+            self.execute_simtalk("StartSim")
+            while self.is_simulation_running():
+                time.sleep(0.01)
\ No newline at end of file
diff --git a/generate_data.py b/generate_data.py
new file mode 100644
index 0000000..39ca482
--- /dev/null
+++ b/generate_data.py
@@ -0,0 +1,20 @@
+import numpy as np
+
+def generate_samples(n_samples):
+
+    losgroesse_1 = []
+    losgroesse_2 = []
+    losgroesse_3 = []
+    bearbzeit_1 = []
+    bearbzeit_2 = []
+    abstandzeit_1 = []
+    for i in range(n_samples):
+
+        losgroesse_1.append(np.random.randint(0,20))
+        losgroesse_2.append(np.random.randint(0,20))
+        losgroesse_3.append(np.random.randint(0,20))
+        bearbzeit_1.append(np.random.randint(30,420))
+        bearbzeit_2.append(np.random.randint(30,420))
+        abstandzeit_1.append(np.random.randint(30,420))
+
+    print(losgroesse_1)
-- 
GitLab