Exemplo n.º 1
0
    def create_child_candidate_from_assignment(self,candidate,assignment):

        new_candidate = Candidate()

        new_candidate.resolved_conflicts = candidate.resolved_conflicts.copy()
        new_candidate.continuously_resolved_cycles = candidate.continuously_resolved_cycles.copy()
        new_candidate.assignments_to_avoid = candidate.assignments_to_avoid.copy()
        new_candidate.assigned_variables = candidate.assigned_variables.copy()

        new_candidate.add_assignments(candidate.assignments)
        if not new_candidate.add_assignment(assignment):
            return None
        new_candidate.add_temporal_relaxations(candidate.temporal_relaxations)
        new_candidate.add_semantic_relaxations(candidate.semantic_relaxations)

        # with this new assignment, find all available/unassigned variables
        for variable in self.tpnu.decision_variables.values():
            # it must not have been assigned
            if not variable in new_candidate.assigned_variables:
                # and the guard must have been satisfied
                if len(variable.guards) == 0 or variable.guards <= new_candidate.assignments:
                    new_candidate.unassigned_variables.put(variable)
                    new_candidate.h += variable.optimal_utility

        return new_candidate
Exemplo n.º 2
0
    def create_child_candidate_from_assignment(self, candidate, assignment):

        new_candidate = Candidate()

        new_candidate.resolved_conflicts = candidate.resolved_conflicts.copy()
        new_candidate.continuously_resolved_cycles = candidate.continuously_resolved_cycles.copy(
        )
        new_candidate.assignments_to_avoid = candidate.assignments_to_avoid.copy(
        )
        new_candidate.assigned_variables = candidate.assigned_variables.copy()

        new_candidate.add_assignments(candidate.assignments)
        if not new_candidate.add_assignment(assignment):
            return None
        new_candidate.add_temporal_relaxations(candidate.temporal_relaxations)
        new_candidate.add_semantic_relaxations(candidate.semantic_relaxations)

        # with this new assignment, find all available/unassigned variables
        for variable in self.tpnu.decision_variables.values():
            # it must not have been assigned
            if not variable in new_candidate.assigned_variables:
                # and the guard must have been satisfied
                if len(variable.guards
                       ) == 0 or variable.guards <= new_candidate.assignments:
                    new_candidate.unassigned_variables.put(variable)
                    new_candidate.h += variable.optimal_utility

        return new_candidate
Exemplo n.º 3
0
    def create_child_candidate_from_relaxations(self,
                                                candidate,
                                                relaxations=None,
                                                allocations=None):

        new_candidate = Candidate()

        new_candidate.resolved_conflicts = candidate.resolved_conflicts.copy()
        new_candidate.continuously_resolved_cycles = candidate.continuously_resolved_cycles.copy(
        )
        new_candidate.assignments_to_avoid = candidate.assignments_to_avoid.copy(
        )
        new_candidate.assigned_variables = candidate.assigned_variables.copy()

        new_candidate.add_assignments(candidate.assignments)
        # We do not need the following line as it adds duplicated relaxations to the
        # new candidate.
        # new_candidate.add_temporal_relaxations(candidate.temporal_relaxations)
        # Add temporal relaxations
        if relaxations is not None:
            for relaxation in relaxations:
                if not new_candidate.add_temporal_relaxation(relaxation):
                    return None

        # Add temporal allocations
        if allocations is not None:
            for allocation in allocations:
                if not new_candidate.add_temporal_allocation(allocation):
                    return None

        new_candidate.add_semantic_relaxations(candidate.semantic_relaxations)

        # find all available variables
        for variable in self.tpnu.decision_variables.values():
            # it must not have been assigned
            if not variable in new_candidate.assigned_variables:
                # and the guard must have been satisfied
                if len(variable.guards
                       ) == 0 or variable.guards <= new_candidate.assignments:
                    new_candidate.unassigned_variables.put(variable)
                    new_candidate.h += variable.optimal_utility

        return new_candidate
Exemplo n.º 4
0
    def create_child_candidate_from_relaxations(self,candidate,relaxations=None,allocations=None):

        new_candidate = Candidate()

        new_candidate.resolved_conflicts = candidate.resolved_conflicts.copy()
        new_candidate.continuously_resolved_cycles = candidate.continuously_resolved_cycles.copy()
        new_candidate.assignments_to_avoid = candidate.assignments_to_avoid.copy()
        new_candidate.assigned_variables = candidate.assigned_variables.copy()

        new_candidate.add_assignments(candidate.assignments)
        # We do not need the following line as it adds duplicated relaxations to the
        # new candidate.
        # new_candidate.add_temporal_relaxations(candidate.temporal_relaxations)
        # Add temporal relaxations
        if relaxations is not None:
            for relaxation in relaxations:
                if not new_candidate.add_temporal_relaxation(relaxation):
                    return None

        # Add temporal allocations
        if allocations is not None:
            for allocation in allocations:
                if not new_candidate.add_temporal_allocation(allocation):
                    return None

        new_candidate.add_semantic_relaxations(candidate.semantic_relaxations)

        # find all available variables
        for variable in self.tpnu.decision_variables.values():
            # it must not have been assigned
            if not variable in new_candidate.assigned_variables:
                # and the guard must have been satisfied
                if len(variable.guards) == 0 or variable.guards <= new_candidate.assignments:
                    new_candidate.unassigned_variables.put(variable)
                    new_candidate.h += variable.optimal_utility

        return new_candidate