# Path: search/temporal_relaxation.py
# class TemporalRelaxation(object):
# 
#     def __init__(self, constraint):
#         self.constraint = constraint
#         self.relaxed_lb = None
#         self.relaxed_ub = None
# 
#     def implement(self):
#         if self.relaxed_lb is not None:
#             self.constraint.relaxed_lb = self.relaxed_lb
# 
#         if self.relaxed_ub is not None:
#             self.constraint.relaxed_ub = self.relaxed_ub
# 
#     def pretty_print(self):
#         if self.relaxed_lb is not None:
#             cost = -1 * abs(self.relaxed_lb - self.constraint.lower_bound) * self.constraint.relax_cost_lb
#             print(str(self.constraint.name) + "(LB): "+ str(self.constraint.lower_bound) +" -> "+str(self.relaxed_lb) + " (" +str(cost)+ ")")
# 
#         if self.relaxed_ub is not None:
#             cost = -1 * abs(self.relaxed_ub - self.constraint.upper_bound) * self.constraint.relax_cost_ub
#             print(str(self.constraint.name) + "(UB): "+ str(self.constraint.upper_bound) +" -> "+str(self.relaxed_ub) + " (" +str(cost)+ ")")


from pulp import solvers, LpProblem, LpVariable, value, LpMaximize
from search.temporal_relaxation import TemporalRelaxation
                import gurobipy

            # exit(0);


        # if no solution was found, do nothing

        if status > 0:
            # A solution has been bound
            # extract the result and store them into a set of relaxation
            # the outcome is a set of relaxations
            relaxations = []
            max_flex_value = value(max_flex_variable)

            for constraint, bound in lp_variables.keys():
                variable = lp_variables[(constraint, bound)]
                relaxed_bound = value(variable)

                if bound == 0:
                    # check if this constraint bound is relaxed
                    if relaxed_bound != constraint.lower_bound:
                        # yes! create a new relaxation for it
                        relaxation = TemporalRelaxation(constraint)
                        relaxation.relaxed_lb = relaxed_bound
                        # relaxation.pretty_print()
                        relaxations.append(relaxation)

                elif bound == 1:
                    # same for upper bound
                    if relaxed_bound != constraint.upper_bound:
                        # yes! create a new relaxation for it

# Path: search/temporal_relaxation.py
# class TemporalRelaxation(object):
# 
#     def __init__(self, constraint):
#         self.constraint = constraint
#         self.relaxed_lb = None
#         self.relaxed_ub = None
# 
#     def implement(self):
#         if self.relaxed_lb is not None:
#             self.constraint.relaxed_lb = self.relaxed_lb
# 
#         if self.relaxed_ub is not None:
#             self.constraint.relaxed_ub = self.relaxed_ub
# 
#     def pretty_print(self):
#         if self.relaxed_lb is not None:
#             cost = -1 * abs(self.relaxed_lb - self.constraint.lower_bound) * self.constraint.relax_cost_lb
#             print(str(self.constraint.name) + "(LB): "+ str(self.constraint.lower_bound) +" -> "+str(self.relaxed_lb) + " (" +str(cost)+ ")")
# 
#         if self.relaxed_ub is not None:
#             cost = -1 * abs(self.relaxed_ub - self.constraint.upper_bound) * self.constraint.relax_cost_ub
#             print(str(self.constraint.name) + "(UB): "+ str(self.constraint.upper_bound) +" -> "+str(self.relaxed_ub) + " (" +str(cost)+ ")")


# Path: search/maxflex_relaxation.py
from pulp import solvers, LpProblem, LpVariable, value, LpMaximize
from search.temporal_relaxation import TemporalRelaxation
                import gurobipy


            # exit(0);


        # if no solution was found, do nothing

        if status > 0:
            # A solution has been bound
            # extract the result and store them into a set of relaxation
            # the outcome is a set of relaxations
            relaxations = []
            max_flex_value = value(max_flex_variable)

            for constraint, bound in lp_variables.keys():
                variable = lp_variables[(constraint, bound)]
                relaxed_bound = value(variable)

                if bound == 0:
                    # check if this constraint bound is relaxed
                    if relaxed_bound != constraint.lower_bound:
                        # yes! create a new relaxation for it
                        relaxation = TemporalRelaxation(constraint)
                        relaxation.relaxed_lb = relaxed_bound
                        # relaxation.pretty_print()
                        relaxations.append(relaxation)

                elif bound == 1:
                    # same for upper bound
                    if relaxed_bound != constraint.upper_bound:
                        # yes! create a new relaxation for it

                        relaxation = TemporalRelaxation(constraint)