def updateValuesMultipleElements(self, state, elements_to_update, quantity_constraints): combinations = [] if len(elements_to_update) != 1: for i in range(0, len(elements_to_update) + 1): combinations += list(itertools.combinations(elements_to_update, i)) else: combinations = [elements_to_update] new_states = [] for combination in combinations: new_state1 = sf.copyState(state) new_state2 = sf.copyState(state) for combination_i in combination: index = combination_i if new_state1.elements[index].derivative == -1: new_state1.elements[index].value = sf.decreaseValue(new_state1.elements[index].value) elif new_state1.elements[index].derivative == 1: new_state1.elements[index].value = sf.increaseValue(new_state1.elements[index].value) new_state2.elements[index].derivative = 0 constraint_check_1 = True constraint_check_2 = True for constraint in quantity_constraints: if not sf.checkConstraint(constraint, new_state1): constraint_check_1 = False if not sf.checkConstraint(constraint, new_state2): constraint_check_2 = False if constraint_check_1: new_states.append(new_state1) if constraint_check_2: new_states.append(new_state2) return new_states
def addInflowChanges(self, state): output_states = [] inflow = state.elements[0] new_state1 = sf.copyState(state) new_state1.elements[0].derivative = 0 new_state2 = sf.copyState(state) if inflow.value == 2: new_state2.elements[0].derivative = -1 elif inflow.value == 0: new_state2.elements[0].derivative = 1 else: if inflow.derivative != 0: new_state2.elements[0].derivative = 0 output_states.append(new_state1) output_states.append(new_state2) return output_states
def applyImmediateRelations(self, state, influences, proportionalities): permutations = list(itertools.permutations(influences + proportionalities)) new_states = [] for permutation in permutations: new_state = sf.copyState(state) for relation in permutation: if relation.type == "Influence": self.applyImmediateInfluence(relation, new_state) else: self.applyImmediateProportion(relation, new_state) new_states.append(new_state) return new_states
def applyTimeRelations(self, state, influences, proportionalities): combined = influences + proportionalities permutations = list(itertools.permutations(combined)) new_states = [] for permutation in permutations: new_state = sf.copyState(state) for permutation_i in permutation: if permutation_i.type == "Influence": self.applyTimeInfluence(permutation_i, new_state) else: self.applyTimeProportion(permutation_i, new_state) new_states.append(new_state) return new_states
def updateTimeValues(self, states, scenario): newly_created_states = [] for state in states: quantity_constraints = scenario.quantity_constraints temp_state = sf.copyState(state) elements_to_update = [] for i in range(len(temp_state.elements)): if temp_state.elements[i].value % 2 != 0 and temp_state.elements[i].derivative != 0: elements_to_update.append(i) newly_created_states += self.updateValuesMultipleElements(temp_state, elements_to_update, quantity_constraints) return newly_created_states
def updateImmediateValues(self, states, scenario): newly_created_states = [] quantity_constraints = scenario.quantity_constraints for state in states: temp_state = sf.copyState(state) for element in temp_state.elements: if element.value % 2 == 0 and element.derivative != 0: if element.derivative == -1: element.value = sf.decreaseValue(element.value) elif element.derivative == 1: element.value = sf.increaseValue(element.value) if not sf.checkStateEquality(state, temp_state): constraint_check = True for constraint in quantity_constraints: if not sf.checkConstraint(constraint, temp_state): constraint_check = False if constraint_check: newly_created_states.append(temp_state) return newly_created_states