ソースを参照

Added some models for live modelling

Yentl Van Tendeloo 7 年 前
コミット
f083aecac4

+ 19 - 0
models/cbd_simple.mvc

@@ -0,0 +1,19 @@
+ConstantBlock cte_x {
+    value = 1
+}
+DelayBlock delay {}
+AdditionBlock adder {}
+NegatorBlock neg {}
+ProbeBlock y {
+    name = "y"
+}
+ProbeBlock z {
+    name = "z"
+}
+
+InitialCondition (cte_x, delay){}
+Link (cte_x, adder) {}
+Link (adder, y) {}
+Link (adder, neg) {}
+Link (neg, adder) {}
+Link (delay, z) {}

+ 61 - 0
models/ctcbd_design.mvc

@@ -0,0 +1,61 @@
+include "primitives.alh"
+
+Class Float {}
+Class String {}
+
+Class Block{}
+Class ICBlock{}
+
+Class ConstantBlock{
+    name = "Constant"
+    value : Float {
+        target_lower_cardinality = 1
+        target_upper_cardinality = 1
+    }
+}
+
+Class AdditionBlock{
+    name = "Addition"
+}
+Class NegatorBlock{
+    name = "Negator"
+}
+Class MultiplyBlock{
+    name = "Multiply"
+}
+Class InverseBlock{
+    name = "Inverse"
+}
+Class DelayBlock{
+    name = "Delay"
+}
+Class IntegratorBlock{
+    name = "Integrator"
+}
+Class DerivatorBlock{
+    name = "Derivator"
+}
+Class ProbeBlock{
+    name = "Probe"
+    name : String {
+        target_lower_cardinality = 1
+        target_upper_cardinality = 1
+    }
+}
+
+Association Link(Block, Block){}
+Association InitialCondition(Block, ICBlock){
+    source_lower_cardinality = 1
+    source_upper_cardinality = 1
+}
+
+Inheritance (ConstantBlock, Block){}
+Inheritance (AdditionBlock, Block){}
+Inheritance (NegatorBlock, Block){}
+Inheritance (MultiplyBlock, Block){}
+Inheritance (InverseBlock, Block){}
+Inheritance (ProbeBlock, Block){}
+Inheritance (ICBlock, Block){}
+Inheritance (DelayBlock, ICBlock){}
+Inheritance (IntegratorBlock, ICBlock){}
+Inheritance (DerivatorBlock, ICBlock){}

+ 53 - 0
models/dtcbd_design.mvc

@@ -0,0 +1,53 @@
+include "primitives.alh"
+
+Class Float {}
+Class String {}
+
+Class Block{}
+Class ICBlock{}
+
+Class ConstantBlock{
+    name = "Constant"
+    value : Float {
+        target_lower_cardinality = 1
+        target_upper_cardinality = 1
+    }
+}
+
+Class AdditionBlock{
+    name = "Addition"
+}
+Class NegatorBlock{
+    name = "Negator"
+}
+Class MultiplyBlock{
+    name = "Multiply"
+}
+Class InverseBlock{
+    name = "Inverse"
+}
+Class DelayBlock{
+    name = "Delay"
+}
+Class ProbeBlock{
+    name = "Probe"
+    name : String {
+        target_lower_cardinality = 1
+        target_upper_cardinality = 1
+    }
+}
+
+Association Link(Block, Block){}
+Association InitialCondition(Block, ICBlock){
+    source_lower_cardinality = 1
+    source_upper_cardinality = 1
+}
+
+Inheritance (ConstantBlock, Block){}
+Inheritance (AdditionBlock, Block){}
+Inheritance (NegatorBlock, Block){}
+Inheritance (MultiplyBlock, Block){}
+Inheritance (InverseBlock, Block){}
+Inheritance (ProbeBlock, Block){}
+Inheritance (ICBlock, Block){}
+Inheritance (DelayBlock, ICBlock){}

+ 76 - 0
models/dtcbd_partial_runtime.mvc

@@ -0,0 +1,76 @@
+include "primitives.alh"
+
+Class Float {}
+Class String {}
+
+Class Block{
+    signal : Float {
+        target_lower_cardinality = 1
+        target_upper_cardinality = 1
+    }
+}
+Class ICBlock{
+    last_in : Float {
+        target_lower_cardinality = 0
+        target_upper_cardinality = 1
+    }
+}
+
+Class ConstantBlock{
+    value : Float {
+        target_lower_cardinality = 1
+        target_upper_cardinality = 1
+    }
+}
+
+Class ProbeBlock{
+    name : String {
+        target_lower_cardinality = 1
+        target_upper_cardinality = 1
+    }
+}
+
+Class AdditionBlock{}
+Class NegatorBlock{}
+Class MultiplyBlock{}
+Class InverseBlock{}
+Class DelayBlock{}
+Class IntegratorBlock{
+    last_out : Float {
+        target_lower_cardinality = 0
+        target_upper_cardinality = 1
+    }
+}
+
+Class DerivatorBlock{}
+Class Time{
+    lower_cardinality = 1
+    upper_cardinality = 1
+
+    start_time : Float {
+        target_lower_cardinality = 1
+        target_upper_cardinality = 1
+    }
+
+    current_time : Float {
+        target_lower_cardinality = 1
+        target_upper_cardinality = 1
+    }
+}
+
+Association Link(Block, Block){}
+Association InitialCondition(Block, ICBlock){
+    source_lower_cardinality = 0
+    source_upper_cardinality = 1
+}
+
+Inheritance (ConstantBlock, Block){}
+Inheritance (AdditionBlock, Block){}
+Inheritance (NegatorBlock, Block){}
+Inheritance (MultiplyBlock, Block){}
+Inheritance (InverseBlock, Block){}
+Inheritance (ICBlock, Block){}
+Inheritance (DelayBlock, ICBlock){}
+Inheritance (DerivatorBlock, ICBlock){}
+Inheritance (IntegratorBlock, ICBlock){}
+Inheritance (ProbeBlock, Block){}

+ 13 - 0
models/fsa_design.mvc

@@ -0,0 +1,13 @@
+include "primitives.alh"
+
+Class String {}
+
+Class State {
+    name = "State"
+    name : String
+}
+
+Association Transition (State, State) {
+    trigger? : String {}
+    raise? : String {}
+}

+ 15 - 0
models/fsa_full_runtime.mvc

@@ -0,0 +1,15 @@
+include "primitives.alh"
+
+Class String {}
+Class Boolean {}
+
+Class State {
+    name = "State"
+    name : String
+    current : Boolean
+}
+
+Association Transition (State, State) {
+    trigger? : String {}
+    raise? : String {}
+}

+ 56 - 0
models/fsa_merge.alc

@@ -0,0 +1,56 @@
+include "primitives.alh"
+include "modelling.alh"
+include "object_operations.alh"
+include "conformance_scd.alh"
+include "utils.alh"
+include "typing.alh"
+include "mini_modify.alh"
+
+String function map_P2F(model : Element, name : String):
+	Element destinations
+	String pick
+
+	destinations = allAssociationDestinations(model, name, "P2F_state")
+
+	pick = name
+	while (pick == name):
+		pick = set_pop(destinations)
+
+	return pick!
+
+Boolean function main(model : Element):
+	Element all_states
+	String element_name
+	Boolean found_current
+	found_current = False
+
+	all_states = allInstances(model, "PartialRuntime/State")
+	while (set_len(all_states) > 0):
+		element_name = set_pop(all_states)
+		if (set_len(allOutgoingAssociationInstances(model, element_name, "P2F_state")) > 0):
+			// Element already exists in full, so copy existing attributes
+            instantiate_attribute(model, element_name, "current", read_attribute(model, map_P2F(model, element_name), "current"))
+			if (read_attribute(model, map_P2F(model, element_name), "current")):
+				found_current = True
+		else:
+            instantiate_attribute(model, element_name, "current", False)
+			instantiate_link(model, "P2F_state", "", element_name, element_name)
+
+	Element all_elements
+	String elem
+	all_elements = dict_keys(model["model"])
+	while (set_len(all_elements) > 0):
+		elem = set_pop(all_elements)
+		if (string_startswith(read_type(model, elem), "PartialRuntime/")):
+			retype(model, elem, "NewFullRuntime/" + cast_string(list_read(string_split_nr(read_type(model, elem), "/", 1), 1)))
+
+	String new_state
+	if (found_current == False):
+		output("FIX_NEW_STATE")
+		new_state = input()
+		while (set_len(all_states) > 0):
+			element_name = set_pop(all_states)
+			if (value_eq(read_attribute(model, element_name, "name"), new_state):
+				instantiate_attribute(model, element_name, "current", True)
+				break!
+	return True!

+ 27 - 0
models/fsa_model.mvc

@@ -0,0 +1,27 @@
+State idle {
+    name = "idle"
+    initial = True
+}
+State armed {
+    name = "armed"
+    initial = False
+}
+State detected {
+    name = "detected"
+    initial = False
+}
+
+Transition (idle, armed) {
+    trigger = "Arm"
+}
+Transition (armed, idle) {
+    trigger = "Disable"
+}
+Transition (armed, detected) {
+    trigger = "PersonDetected"
+    raise = "SoundAlarm"
+}
+Transition (detected, armed) {
+    trigger = "CorrectCode"
+    raise = "DisableAlarm"
+}

+ 14 - 0
models/fsa_partial_runtime.mvc

@@ -0,0 +1,14 @@
+include "primitives.alh"
+
+Class String {}
+Class Boolean {}
+
+Class State {
+    name = "State"
+    name : String
+}
+
+Association Transition (State, State) {
+    trigger? : String {}
+    raise? : String {}
+}

+ 40 - 0
models/fsa_simulate.alc

@@ -0,0 +1,40 @@
+include "primitives.alh"
+include "modelling.alh"
+include "object_operations.alh"
+include "conformance_scd.alh"
+include "io.alh"
+include "metamodels.alh"
+include "mini_modify.alh"
+
+Boolean function main(model : Element):
+	String input_value
+	Float start_time
+	String current_state
+	Element transitions
+	String transition
+
+	start_time = time()
+
+	while (True):
+		if (has_input()):
+			input_value = input()
+
+			if (input_value == "__EXIT__"):
+				break!
+
+			transitions = allOutgoingAssociationInstances(model, current_state)
+			while (set_len(transitions) > 0):
+				transition = set_pop(transitions)
+				if (read_attribute(model, transition, "trigger") == input_value):
+					if (element_neq(read_attribute(model, transition, "raise"), read_root())):
+						output(cast_value(time() - start_time) + " ! " + cast_value(read_attribute(model, transition, "raise")))
+					instantiate_attribute(model, current_state, "current", False)
+					current_state = readAssociationDestination(model, transition)
+					instantiate_attribute(model, current_state, "current", True)
+					break!
+
+		output(cast_value(time() - start_time) + " : " + cast_value(read_attribute(model, current_state, "name")))
+		sleep(0.2)
+
+	output("CLOSE")
+	return True!

+ 47 - 0
models/fsa_toRuntime.alc

@@ -0,0 +1,47 @@
+include "primitives.alh"
+include "modelling.alh"
+include "object_operations.alh"
+
+String function map_D2P(model : Element, name : String):
+	Element destinations
+	String pick
+
+	destinations = allAssociationDestinations(model, name, "D2P_state")
+
+	pick = name
+	while (pick == name):
+		pick = set_pop(destinations)
+
+	return pick!
+
+Boolean function main(model : Element):
+	Element all_states
+	String element_name
+	String new_element_name
+	String mm_type_name
+	Element all_links
+
+	all_states = allInstances(model, "Design/State")
+	while (set_len(all_states) > 0):
+		element_name = set_pop(all_states)
+		mm_type_name = "PartialRuntime/" + cast_string(list_read(string_split(read_type(model, element_name), "/"), 1))
+
+		if (set_len(allOutgoingAssociationInstances(model, element_name, "D2P_state")) == 0):
+			// New design element, so create in partial runtime model as well
+			new_element_name = instantiate_node(model, mm_type_name, "")
+			instantiate_link(model, "D2P_state", "", element_name, new_element_name)
+
+		// Always update the value of attributes of PartialRuntime
+		new_element_name = map_D2P(model, element_name)
+        instantiate_attribute(model, new_element_name, "name", read_attribute(model, element_name, "name"))
+        instantiate_attribute(model, new_element_name, "initial", read_attribute(model, element_name, "initial"))
+
+	// Recreate all transitions
+    all_links = allInstances(model, "Design/Transition")
+    while (set_len(all_links) > 0):
+        element_name = set_pop(all_links)
+        new_element_name = instantiate_link(model, "PartialRuntime/Transition", "", map_D2P(model, readAssociationSource(model, element_name)), map_D2P(model, readAssociationDestination(model, element_name)))
+		instantiate_attribute(model, new_element_name, "trigger", read_attribute(model, element_name, "trigger"))
+		instantiate_attribute(model, new_element_name, "raise", read_attribute(model, element_name, "raise"))
+
+	return True!

+ 288 - 0
models/pm_req_analyse_print.mvc

@@ -0,0 +1,288 @@
+Start start {}
+Finish finish {}
+
+Exec revise_req {
+    name = "models/revise_req"
+}
+Exec make_initial_models {
+    name = "models/make_initial_models"
+}
+
+Fork fork1 {}
+
+Exec revise_plant {
+    name = "models/revise_plant"
+}
+Exec revise_environment {
+    name = "models/revise_environment"
+}
+Exec revise_control {
+    name = "models/revise_control"
+}
+Exec revise_query {
+    name = "models/revise_query"
+}
+Exec revise_architecture {
+    name = "models/revise_architecture"
+}
+
+Exec plant_to_EPN {
+    name = "models/plant_to_EPN"
+}
+Exec environment_to_EPN {
+    name = "models/environment_to_EPN"
+}
+
+Exec control_to_EPN {
+    name = "models/control_to_EPN"
+}
+
+Join join2 {}
+
+Exec merge_EPN {
+    name = "models/merge_EPN"
+}
+
+Exec combine_EPN {
+    name = "models/combine_EPN"
+}
+
+Exec EPN_to_PN {
+    name = "models/EPN_to_PN"
+}
+
+Exec analyse {
+    name = "models/reachability"
+}
+
+Join join3 {}
+
+Exec match {
+    name = "models/match"
+}
+
+Exec bfs {
+    name = "models/bfs"
+}
+
+Exec reachability_print {
+    name = "models/reachability_graph_print"
+}
+
+Decision found {}
+
+Data req {
+    name = "requirements"
+    type = "formalisms/Requirements"
+}
+Data plant_model {
+    name = "plant_model"
+    type = "formalisms/PW_Plant"
+}
+Data environment_model {
+    name = "environment_model"
+    type = "formalisms/PW_Environment"
+}
+Data control_model {
+    name = "control_model"
+    type = "formalisms/PW_Control"
+}
+Data plant_EPN {
+    name = "plant_EPN"
+    type = "formalisms/Encapsulated_PetriNet"
+}
+Data control_EPN {
+    name = "control_EPN"
+    type = "formalisms/Encapsulated_PetriNet"
+}
+Data environment_EPN {
+    name = "environment_EPN"
+    type = "formalisms/Encapsulated_PetriNet"
+}
+Data pn {
+    name = "pn"
+    type = "formalisms/PetriNet"
+}
+Data reachability_graph {
+    name = "reachability"
+    type = "formalisms/ReachabilityGraph"
+}
+Data query {
+    name = "query"
+    type = "formalisms/Query"
+}
+Data architecture {
+    name = "architecture"
+    type = "formalisms/Architecture"
+}
+Data merged_EPN {
+    name = "merged_EPN"
+    type = "formalisms/Encapsulated_PetriNet"
+}
+
+Next (start, make_initial_models) {}
+Next (make_initial_models, revise_req) {}
+Next (revise_req, fork1) {}
+Next (fork1, revise_plant) {}
+Next (fork1, revise_environment) {}
+Next (fork1, revise_control) {}
+Next (fork1, revise_query) {}
+Next (fork1, revise_architecture) {}
+Next (revise_plant, plant_to_EPN) {}
+Next (revise_environment, environment_to_EPN) {}
+Next (revise_control, control_to_EPN) {}
+Next (plant_to_EPN, join2) {}
+Next (environment_to_EPN, join2) {}
+Next (control_to_EPN, join2) {}
+Next (revise_architecture, join2) {}
+Next (join2, merge_EPN) {}
+Next (merge_EPN, combine_EPN) {}
+Next (combine_EPN, analyse) {}
+Next (analyse, join3) {}
+Next (revise_query, join3) {}
+Next (join3, match) {}
+Next (match, found) {}
+Then (found, bfs) {}
+Next (bfs, fork1) {}
+Else (found, reachability_print) {}
+Next (reachability_print, finish) {}
+
+Consumes (revise_req, req) {
+    name = "Requirements"
+}
+Produces (revise_req, req) {
+    name = "Requirements"
+}
+
+Produces (make_initial_models, plant_model) {
+    name = "PW_Plant"
+}
+Produces (make_initial_models, environment_model) {
+    name = "PW_Environment"
+}
+Produces (make_initial_models, control_model) {
+    name = "PW_Control"
+}
+Produces (make_initial_models, query) {
+    name = "Query"
+}
+Produces (make_initial_models, architecture) {
+    name = "Architecture"
+}
+Produces (make_initial_models, req) {
+    name = "Requirements"
+}
+
+Consumes (revise_plant, req) {
+    name = "Requirements"
+}
+Consumes (revise_environment, req) {
+    name = "Requirements"
+}
+Consumes (revise_control, req) {
+    name = "Requirements"
+}
+Consumes (revise_query, req) {
+    name = "Requirements"
+}
+Consumes (revise_architecture, req) {
+    name = "Requirements"
+}
+
+Consumes (revise_plant, plant_model) {
+    name = "PW_Plant"
+}
+Consumes (revise_environment, environment_model) {
+    name = "PW_Environment"
+}
+Consumes (revise_control, control_model) {
+    name = "PW_Control"
+}
+Consumes (revise_query, query) {
+    name = "Query"
+}
+Consumes (revise_architecture, architecture) {
+    name = "Architecture"
+}
+Produces (revise_plant, plant_model) {
+    name = "PW_Plant"
+}
+Produces (revise_control, control_model) {
+    name = "PW_Control"
+}
+Produces (revise_environment, environment_model) {
+    name = "PW_Environment"
+}
+Produces (revise_query, query) {
+    name = "Query"
+}
+Produces (revise_architecture, architecture) {
+    name = "Architecture"
+}
+
+Consumes (plant_to_EPN, plant_model) {
+    name = "PW_Plant"
+}
+Produces (plant_to_EPN, plant_EPN) {
+    name = "Encapsulated_PetriNet"
+}
+Consumes (environment_to_EPN, environment_model) {
+    name = "PW_Environment"
+}
+Produces (environment_to_EPN, environment_EPN) {
+    name = "Encapsulated_PetriNet"
+}
+Consumes (control_to_EPN, control_model) {
+    name = "PW_Control"
+}
+Produces (control_to_EPN, control_EPN) {
+    name = "Encapsulated_PetriNet"
+}
+
+Consumes (merge_EPN, environment_EPN) {
+    name = "EPN_Environment"
+}
+Consumes (merge_EPN, control_EPN) {
+    name = "EPN_Control"
+}
+Consumes (merge_EPN, plant_EPN) {
+    name = "EPN_Plant"
+}
+Produces (merge_EPN, merged_EPN) {
+    name = "Encapsulated_PetriNet"
+}
+
+Consumes (combine_EPN, merged_EPN) {
+    name = "Encapsulated_PetriNet"
+}
+Consumes (combine_EPN, architecture) {
+    name = "Architecture"
+}
+Produces (combine_EPN, pn) {
+    name = "PetriNet"
+}
+
+Consumes (analyse, pn) {
+    name = "PetriNet"
+}
+Produces (analyse, reachability_graph) {
+    name = "ReachabilityGraph"
+}
+
+Consumes (match, reachability_graph) {
+    name = "ReachabilityGraph"
+}
+Consumes (match, query) {
+    name = "Query"
+}
+Produces (match, reachability_graph) {
+    name = "ReachabilityGraph"
+}
+
+Consumes (bfs, reachability_graph) {
+    name = "ReachabilityGraph"
+}
+
+Consumes (reachability_print, reachability_graph) {
+    name = "ReachabilityGraph"
+}