本文整理汇总了Python中writer.Writer.clear方法的典型用法代码示例。如果您正苦于以下问题:Python Writer.clear方法的具体用法?Python Writer.clear怎么用?Python Writer.clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类writer.Writer
的用法示例。
在下文中一共展示了Writer.clear方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CountertraceFinder
# 需要导入模块: from writer import Writer [as 别名]
# 或者: from writer.Writer import clear [as 别名]
#.........这里部分代码省略.........
current_set_of_states = utils.keep_only_present(next_states)
# If we are here, we found an input for every time step.
repeat_index = self.get_index_of_superset_in_list(list_of_sets, \
current_set_of_states) + 1
trace = InfiniteTraceOfBdds(utils, countertrace, repeat_index)
return trace
def print_trace(self, countertrace):
"""
Prints a countertrace into the file
./spec_debug_results/countertrace.txt.
@param countertrace: A sequence of inputs so that the system is forced
to violate its specification.
@type countertrace: L{InfiniteTraceOfBdds}
"""
# write the inputs according to the countertrace:
for input_bdd in countertrace.get_trace():
for var in self.__utils.input_vars:
symb = self.__utils.get_val_as_string(input_bdd, var, False)
self.__writer.set_chosen_input(var.name, symb)
self.__writer.start_next_time_step()
# finally we define where the trace repeats:
self.__writer.set_repeat_indices(countertrace.repeat_index, \
countertrace.length_stem_plus_loop - 1)
# and write the file:
self.__writer.write_to_file("./spec_debug_results/countertrace.txt")
self.__writer.clear()
def is_graph_system_independent(self, graph_nodes):
"""
Checks if the inputs in a graph are system independent.
This method checks if the inputs in the graph computed by the class
L{PathFinder} are system independent. If this is the case, a
countertrace can be read directly from this graph. If the graph was
generated from a countertrace, the inputs in this graph will always
be system independent (i.e., independent of the moves of the system).
This method is only used to check if the methods compute_countertrace
and make_strategy_system_independent work correctly.
@param graph_nodes: A set of graph nodes.
@type graph_nodes: list<L{GraphNode}>
@return: True if the graph is system independent, False otherwise
@rtype: bool
"""
# The first current state is the initial state:
current_nodes = [graph_nodes[0]]
current_nodes_bdd = graph_nodes[0].bdd
list_of_sets = []
while list_of_sets.count(current_nodes_bdd) == 0:
list_of_sets.append(current_nodes_bdd)
# check if all inputs are equal:
input_intersection = BDD.ONE(self.__utils.dd_mgr)
for node in current_nodes:
inputs = self.__utils.keep_only_present_inputs(node.bdd)
input_intersection *= inputs
示例2: InteractiveGame
# 需要导入模块: from writer import Writer [as 别名]
# 或者: from writer.Writer import clear [as 别名]
#.........这里部分代码省略.........
"""
# While the user enters variable values that are not allowed by
# the transition relation of the system (if valid values are entered,
# we jump out of the loop with a return):
while True:
all_outvars_bdd = BDD.ONE(self.__utils.dd_mgr)
for out_var in self.__utils.relevant_out_vars:
(out_bdd, quit) = self._read_single_out_var(out_var, \
all_outvars_bdd * possible_outputs)
if quit:
return (None, True)
all_outvars_bdd *= out_bdd
# check if the entered values are possible according to the
# transition relation of the system (which is already part of
# $possible_outputs)
if (possible_outputs * all_outvars_bdd).isNotZero():
return (all_outvars_bdd, False)
print "this is not possible according to the transition relation"
print "try again"
def _read_single_out_var(self, out_var, possible_next_outputs):
"""
Reads one single next output value from STDIN.
This method asks the user to enter the next value of one single output
variables of the system. It also resolves all restrictions on the
variable (due to the transition relation of the system and previously
entered variables) and displays possible values for the variable
in brackets:
- enter next hgrant0 (1): means only 1 is allowed for the next hgrant0
- enter next hgrant0 (0): means only 0 is allowed for the next hgrant0
- enter next hgrant0 (0,1): means that you can pick whatever you want
The user is only allowed to enter '0', '1' or 'Q' if she wants to
quit the game.
@param out_var: The output variable to choose.
@type out_var: L{Variable}
@param possible_next_outputs: A bdd with all possible next outputs.
@type possible_next_outputs: L{BDD}
@return: A tuple (outvar_bdd, quit) where:
- outvar_bdd is a bdd with all next output variables set to
the values entered by the user
- quit is True if the user wants to quit and False otherwise.
@rtype: (L{BDD}, int)
"""
# while the user enteres invalid values (otherwise we jump out of
# the loop with the return):
while True:
print "enter next " + out_var.name,
self._print_possible_values_for(out_var, possible_next_outputs)
input_line = sys.stdin.readline()
if input_line == "Q\n" or input_line == "q\n":
print "quit by user";
self.__writer.write_to_file("./spec_debug_results/log.txt")
self.__writer.clear()
return (None, True)
if input_line == "1\n":
return (out_var.ns, False)
elif input_line == "0\n":
return (~out_var.ns, False)
print "enter '1' or '0' or 'Q' to quit"
def _print_possible_values_for(self, out_var, restrictions):
"""
Prints all values which are possible for a certain output.
This method prints all possible values for a certain output variable
to STDOUT and also writes the values to a file
'spec_debug_results/log.txt'.
Writing to the file is done with the L{Writer} which formats
the output in a nice way.
@param out_var: The variable to print the possible values for.
@type out_var: L{Variable}
@param restrictions: A bdd with all restrictions on the next output
variables.
@type restrictions: L{BDD}
"""
(can_be_1, can_be_0) = self.__utils.get_val(restrictions, out_var, True)
if can_be_1 and can_be_0:
sys.stdout.write(" (0,1): ")
self.__writer.set_possibilities(out_var.name, "(0,1)")
elif can_be_1:
sys.stdout.write(" (1): ")
self.__writer.set_possibilities(out_var.name, "( 1 )")
elif can_be_0:
sys.stdout.write(" (0): ")
self.__writer.set_possibilities(out_var.name, "( 0 )")
else:
sys.stdout.write(" (): ")
self.__writer.set_possibilities(out_var.name, "( )")