<commit_before>"""Function(s) that creates a Stateflow diagram from a Mealy Machine."""


import numpy
import copy
from tulip.transys import Mealy
import pdb


def to_stateflow(TS, filename):
	"""Converts a Mealy Machine to a Stateflow diagram.
	
	Inputs:
		- TS: an instance of tulip.transys.machines.Mealy()
		- filename: a string that is the valid filename of a MATLAB script
		  (must end in '.m')

	The function has no Python outputs, it writes a MATLAB script that will
	create a Simulink model with a Stateflow chart containing a Mealy Machine
	when run.
	"""

	# Check that the filename ends in ".m"
	if filename[-2:] != ".m":
		print "Filename must end in '.m'"
		raise

	# Get the intro text
	head_text = "sfnew('-Mealy','Tulip Controller');\n"
	head_text = head_text + "root = sfroot;\n"
	head_text = head_text + "m = root.find('-isa', 'Simulink.BlockDiagram');\n"
	head_text = head_text + "ch = m.find('-isa', 'Stateflow.Chart');\n"
	head_text = head_text + "ch.Name = 'TulipFSM';\n\n"

	# Get list of nodes and add to Stateflow
	state_list = TS.states.find()
	num_nodes = len(state_list)
	node_positions = get_positions(num_nodes)
	(state_string, states_dict) = write_states(state_list, node_positions)

	# Get list of transitions and add to Stateflow
	transitions_list = TS.transitions.find()
	inputs = TS.inputs.keys()
	outputs = TS.outputs.keys()
	transitions_string = write_transitions(transitions_list, inputs, outputs,
		states_dict)

	# Get default transition for initial state
	initial_transitions = TS.transitions.find(from_states=('Sinit',))
#	initial_states = []
#	for initial_transition in initial_transitions:
#		initial_states.append(initial_transition[1])
	initial_str = write_init_string(initial_transitions, states_dict, inputs)
<commit_msg>Removing Sinit from list of states exported.<commit_after>"""Function(s) that creates a Stateflow diagram from a Mealy Machine."""


import numpy
import copy
from tulip.transys import Mealy
import pdb


def to_stateflow(TS, filename):
	"""Converts a Mealy Machine to a Stateflow diagram.
	
	Inputs:
		- TS: an instance of tulip.transys.machines.Mealy()
		- filename: a string that is the valid filename of a MATLAB script
		  (must end in '.m')

	The function has no Python outputs, it writes a MATLAB script that will
	create a Simulink model with a Stateflow chart containing a Mealy Machine
	when run.
	"""

	# Check that the filename ends in ".m"
	if filename[-2:] != ".m":
		print "Filename must end in '.m'"
		raise

	# Get the intro text
	head_text = "sfnew('-Mealy','Tulip Controller');\n"
	head_text = head_text + "root = sfroot;\n"
	head_text = head_text + "m = root.find('-isa', 'Simulink.BlockDiagram');\n"
	head_text = head_text + "ch = m.find('-isa', 'Stateflow.Chart');\n"
	head_text = head_text + "ch.Name = 'TulipFSM';\n\n"

	# Get list of nodes (remove Sinit from list) and add to Stateflow`
	state_list = TS.states.find()
	sinit = TS.states.find('Sinit')[0]
	sinit_index = state_list.index(sinit)
	state_list.pop(sinit_index)
	num_nodes = len(state_list)
	node_positions = get_positions(num_nodes)
	(state_string, states_dict) = write_states(state_list, node_positions)

	# Get list of transitions (remove those from Sinit) and add to Stateflow
	transitions_list = TS.transitions.find()
	tsinit_list = TS.transitions.find(from_states=('Sinit',))
	for transition in tsinit_list:
		index = transitions_list.index(transition)
		transitions_list.pop(index)
	inputs = TS.inputs.keys()
	outputs = TS.outputs.keys()
	transitions_string = write_transitions(transitions_list, inputs, outputs,
		states_dict)

	# Get default transition for initial state
	initial_transitions = TS.transitions.find(from_states=('Sinit',))
	initial_str = write_init_string(initial_transitions, states_dict, inputs)

{'fraction_non_alphanumeric': 0.1114936440677966, 'fraction_numerical': 0.001059322033898305, 'mean_word_length': 4.792944785276074, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3848643', 'n_tokens_mistral': 1314, 'n_tokens_neox': 1250, 'n_words': 376}