示例#1
0
    def __init__(self, task_queue, result_queue, cfr, timeQueue, index,
                 outputFileParentName, num_consumers, s, metrics_variables,
                 metrics_objective_direction, consumerConstraints):
        multiprocessing.Process.__init__(self)
        self.task_queue = task_queue
        self.result_queue = result_queue
        self.timeQueue = timeQueue
        self.cfr = cfr
        self.solver = s
        self.consumerConstraints = consumerConstraints
        self.index = index
        self.num_consumers = num_consumers
        self.ParetoFront = []
        self.clock = Clock()
        self.GIAOptions = GuidedImprovementAlgorithmOptions(verbosity=0, \
                        incrementallyWriteLog=False, \
                        writeTotalTimeFilename="timefile.csv", \
                        writeRandomSeedsFilename="randomseed.csv", useCallLogs=False)

        self.GIAAlgorithm = GuidedImprovementAlgorithm(self.cfr, self.solver, metrics_variables, \
                    metrics_objective_direction, [], options=self.GIAOptions)
示例#2
0
    def GIA(self, desired_number_of_models):
        metrics_objective_direction = []
        metrics_variables = []

        for i in self.objectives:
            (pol, var) = i
            metrics_objective_direction.append(pol)
            metrics_variables.append(var)

        # Non-Parallel    
        GIAOptionsNP = GuidedImprovementAlgorithmOptions(verbosity=0, \
            incrementallyWriteLog=False, \
            writeTotalTimeFilename="timefile.csv", \
            writeRandomSeedsFilename="randomseed.csv", useCallLogs=False, num_models=desired_number_of_models, magnifying_glass=Options.MAGNIFYING_GLASS)    
        if Options.CORES == 1:
            GIAAlgorithmNP = GuidedImprovementAlgorithm(self, self.solver, metrics_variables, \
                    metrics_objective_direction, [], options=GIAOptionsNP) 
            '''featurevars instead of []'''
            outfilename = str("giaoutput").strip()
    
            ParetoFront = GIAAlgorithmNP.ExecuteGuidedImprovementAlgorithm(outfilename)
            if not Options.SUPPRESS_MODELS:
                if not ParetoFront:
                    standard_print("UNSAT")
                for i in ParetoFront:
                    self.printVars(i)
            return ParetoFront
        else:
            parSolver = ParSolver.ParSolver(self, self.module, self.solver, metrics_variables, metrics_objective_direction)
            ParetoFront = parSolver.run()   
            for i in ParetoFront:
                self.printStartDelimeter()
                standard_print(i)
                standard_print("")
                self.printEndDelimeter()
            return ParetoFront
示例#3
0
 def __init__(self, task_queue, result_queue, cfr, timeQueue, index, outputFileParentName, num_consumers, s, metrics_variables, metrics_objective_direction, consumerConstraints):
     multiprocessing.Process.__init__(self)
     self.task_queue = task_queue
     self.result_queue = result_queue
     self.timeQueue = timeQueue 
     self.cfr = cfr
     self.solver = s
     self.consumerConstraints = consumerConstraints
     self.index = index
     self.num_consumers = num_consumers
     self.ParetoFront = []
     self.clock = Clock()
     self.GIAOptions = GuidedImprovementAlgorithmOptions(verbosity=0, \
                     incrementallyWriteLog=False, \
                     writeTotalTimeFilename="timefile.csv", \
                     writeRandomSeedsFilename="randomseed.csv", useCallLogs=False)    
     
     self.GIAAlgorithm = GuidedImprovementAlgorithm(self.cfr, self.solver, metrics_variables, \
                 metrics_objective_direction, [], options=self.GIAOptions)
示例#4
0
class GIAConsumer(multiprocessing.Process):
    def __init__(self, task_queue, result_queue, cfr, timeQueue, index,
                 outputFileParentName, num_consumers, s, metrics_variables,
                 metrics_objective_direction, consumerConstraints):
        multiprocessing.Process.__init__(self)
        self.task_queue = task_queue
        self.result_queue = result_queue
        self.timeQueue = timeQueue
        self.cfr = cfr
        self.solver = s
        self.consumerConstraints = consumerConstraints
        self.index = index
        self.num_consumers = num_consumers
        self.ParetoFront = []
        self.clock = Clock()
        self.GIAOptions = GuidedImprovementAlgorithmOptions(verbosity=0, \
                        incrementallyWriteLog=False, \
                        writeTotalTimeFilename="timefile.csv", \
                        writeRandomSeedsFilename="randomseed.csv", useCallLogs=False)

        self.GIAAlgorithm = GuidedImprovementAlgorithm(self.cfr, self.solver, metrics_variables, \
                    metrics_objective_direction, [], options=self.GIAOptions)

    def addParetoPoints(self, point):
        self.ParetoFront.append(point)

    def run(self):
        num_solutions = 0
        self.clock.tick("Consumer " + str(self.index))
        while True:
            next_task = self.task_queue.get()
            try:
                if next_task == "Poison" or (num_solutions
                                             == Options.NUM_INSTANCES):
                    self.task_queue.task_done()
                    break
            except:
                pass
            self.solver.push()

            self.solver.add(self.consumerConstraints[int(next_task)])
            self.consumerConstraints[int(next_task)]
            self.clock.tick("Task " + str(next_task))
            total_sat_calls = 0
            total_unsat_time = 0
            while True:
                if self.GIAAlgorithm.s.check(
                ) != Common.SAT or num_solutions == Options.NUM_INSTANCES:
                    self.clock.tock("Task " + str(next_task))
                    self.task_queue.task_done()
                    self.solver.pop()
                    break
                else:
                    prev_solution = self.GIAAlgorithm.s.model()
                    self.GIAAlgorithm.s.push()
                    NextParetoPoint, _local_count_unsat_calls, _local_count_unsat_calls = self.GIAAlgorithm.ranToParetoFront(
                        prev_solution)
                    self.addParetoPoints(NextParetoPoint)
                    metric_values = self.GIAAlgorithm.get_metric_values(
                        NextParetoPoint)
                    self.result_queue.put(
                        (model_to_string(self.cfr,
                                         NextParetoPoint), metric_values))

                    self.GIAAlgorithm.s.pop()
                    tmpNotDominatedByNextParetoPoint = self.GIAAlgorithm.ConstraintNotDominatedByX(
                        NextParetoPoint)
                    self.GIAAlgorithm.s.add(tmpNotDominatedByNextParetoPoint)
                    num_solutions = num_solutions + 1
        self.clock.tock("Consumer " + str(self.index))
        print("Total Sat Calls: " + total_sat_calls)
        print("Total Unsat Time: " + total_unsat_time)
        self.timeQueue.put(self.clock)
        return 0
示例#5
0
class GIAConsumer(multiprocessing.Process):
    def __init__(self, task_queue, result_queue, cfr, timeQueue, index, outputFileParentName, num_consumers, s, metrics_variables, metrics_objective_direction, consumerConstraints):
        multiprocessing.Process.__init__(self)
        self.task_queue = task_queue
        self.result_queue = result_queue
        self.timeQueue = timeQueue 
        self.cfr = cfr
        self.solver = s
        self.consumerConstraints = consumerConstraints
        self.index = index
        self.num_consumers = num_consumers
        self.ParetoFront = []
        self.clock = Clock()
        self.GIAOptions = GuidedImprovementAlgorithmOptions(verbosity=0, \
                        incrementallyWriteLog=False, \
                        writeTotalTimeFilename="timefile.csv", \
                        writeRandomSeedsFilename="randomseed.csv", useCallLogs=False)    
        
        self.GIAAlgorithm = GuidedImprovementAlgorithm(self.cfr, self.solver, metrics_variables, \
                    metrics_objective_direction, [], options=self.GIAOptions)
        
    def addParetoPoints(self, point):
        self.ParetoFront.append(point)
            
    def run(self):
        num_solutions = 0
        self.clock.tick("Consumer " + str(self.index))
        while True:
            next_task = self.task_queue.get()
            try:
                if next_task == "Poison" or (num_solutions == Options.NUM_INSTANCES):
                    self.task_queue.task_done()
                    break
            except:
                pass    
            self.solver.push()
            
            self.solver.add(self.consumerConstraints[int(next_task)])
            self.consumerConstraints[int(next_task)]
            self.clock.tick("Task " + str(next_task))
            total_sat_calls = 0
            total_unsat_time = 0
            while True:
                if self.GIAAlgorithm.s.check() != Common.SAT or num_solutions == Options.NUM_INSTANCES:
                    self.clock.tock("Task " + str(next_task))
                    self.task_queue.task_done()
                    self.solver.pop()
                    break
                else:  
                    prev_solution = self.GIAAlgorithm.s.model()
                    self.GIAAlgorithm.s.push()
                    NextParetoPoint, _local_count_unsat_calls, _local_count_unsat_calls = self.GIAAlgorithm.ranToParetoFront(prev_solution)
                    self.addParetoPoints(NextParetoPoint)
                    metric_values = self.GIAAlgorithm.get_metric_values(NextParetoPoint)
                    self.result_queue.put((model_to_string(self.cfr, NextParetoPoint), metric_values))

                    self.GIAAlgorithm.s.pop()
                    tmpNotDominatedByNextParetoPoint = self.GIAAlgorithm.ConstraintNotDominatedByX(NextParetoPoint)
                    self.GIAAlgorithm.s.add(tmpNotDominatedByNextParetoPoint)
                    num_solutions = num_solutions +  1
        self.clock.tock("Consumer " + str(self.index))
        print("Total Sat Calls: " + total_sat_calls)
        print("Total Unsat Time: " + total_unsat_time)
        self.timeQueue.put(self.clock)
        return 0