Exemple #1
0
	def get_function_values(self, state):
		variables_values = {n: self.fg.variables[n].domain[state[self.neighbours_indecies[n]]] for n in self.neighbours_indecies}
		variables_values[self.name] = self.fg.variables[self.name].domain[state[0]]

		functions = Functions(self.fg)

		function_values = []
		for f in self.variable.functions:
			function_values.append(functions.calculate(f, variables_values))

		return tuple(function_values)
Exemple #2
0
	def get_possible_moves(self):
		variable = [self.name] + [n for n in self.neighbours_indecies]
		index = {n:0 for n in self.neighbours_indecies}
		index[self.name] = 0
		domain = {n:[-1, 0, +1] for n in self.neighbours_indecies}
		domain[self.name] = [-1, 0, +1]
		actions = {-1: 'dec', 0:'hold', 1:'inc'}

		new_points = {'dec': [], 'hold': [], 'inc': []}

		functions = Functions(self.fg)

		while index[variable[0]] < len(domain[variable[0]]):
			new_state = []
			action_profile = []
			variables_values = {}

			all_in_boundaries = True
			for v in variable:
				value = self.state[0]
				if v in self.neighbours_indecies:
					value = self.state[self.neighbours_indecies[v]]

				i = value + domain[v][index[v]]
				if i >= 0 and i < self.fg.variables[v].domain_size:
					new_state.append(i)
					action_profile.append(actions[domain[v][index[v]]])
					variables_values[v] = self.fg.variables[v].domain[i]
				else:
					all_in_boundaries = False
					break

			if all_in_boundaries:
				function_values = []
				for f in self.variable.functions:
					function_values.append(functions.calculate(f, variables_values))

				# format: ((action-profile, state), function-values)
				new_points[action_profile[0]].append(((tuple(action_profile), tuple(new_state)), tuple(function_values)))
			
			for i in reversed(variable):
				if index[i] < len(domain[i]):
					index[i] += 1
					if index[i] == len(domain[i]):
						if i != variable[0]:
							index[i] = 0
					else:
						break

		return new_points
Exemple #3
0
	def get_function_values(self, variables_values):
		values = {}
		calculator = Functions(self.fg)
		for f in self.fg.functions:
			values[f] = calculator.calculate(f, variables_values)
		return values
Exemple #4
0
	def get_value(self, values):
		function = Functions(self.fg)
		return function.calculate(self.name, values)
Exemple #5
0
 def get_value(self, values):
     function = Functions(self.fg)
     return function.calculate(self.name, values)