Beispiel #1
0
def _test():
  from problems.feature_models.webportal import WebPortal
  from problems.problem import Point
  problem = WebPortal()
  points = [Point(one, problem) for one in problem.populate(50)]
  print(len(points))
  selected = select(problem, points, 25)
  print(len(selected))
Beispiel #2
0
def _single_test(repeat=0):
    experiment = sys.argv[1]
    problem = None
    if experiment == "SHP":
        INPUT = SHP_Min
        setRecordPoint(True)
        return
    elif experiment == "WPT":
        INPUT = WPT_Min
        problem = WebPortal()
    elif experiment == "ERS":
        INPUT = ERS_Min
        problem = EmergencyResponse()
    else:
      return

    num_consumers = int(str(sys.argv[3]).strip())
    solvers = replicateSolver(INPUT.s, num_consumers)
    outputFileParentName = str(sys.argv[2]).strip()

    # Establish communication queues
    mgr = multiprocessing.Manager()
    taskQueue = []
    for i in xrange(num_consumers):
        taskQueue.append(mgr.Queue())
    ParetoFront = mgr.Queue()
    totalTime = mgr.Queue()

    # Enqueue initial tasks
    for i in xrange(num_consumers):
        taskQueue[i].put("Task")

    # Start consumers
    consumersList = [ Consumer(taskQueue, ParetoFront, totalTime, i, outputFileParentName, num_consumers, solvers[i], INPUT)
                    for i in xrange(num_consumers)]
    starttime = time.time()
    for w in consumersList:
        w.start()

    for w in consumersList:
        w.join()

    runningtime = 0.0
    while totalTime.qsize() > 0:
        ttime = totalTime.get()
        if (float(ttime) < runningtime):
            runningtime = float(ttime)

    endtime = time.time()

    TotalOverlappingParetoFront = ParetoFront.qsize()
    pf = []
    while not ParetoFront.empty():
        pf.append(ParetoFront.get())
    pf = problem.convert_to_points(pf)
    pf = sel_nsga2(problem, pf, Cons.default_settings().GALE_pop_size)
    new_dir = mkdir("results/"+str(datetime.date.today())+"/")
    outputFileParent = open(new_dir+str(outputFileParentName+'.csv'), 'a')
    try:
        # keep a zero position for the same merging program as opGIA
        # in fact, here zero should be 356, as we already check it using the above code
        outputFileParent.writelines(str(num_consumers) + ',' + str(TotalOverlappingParetoFront) +',' + '0' + ',' + str(endtime - starttime) + '\n')
    finally:
        outputFileParent.close()
    obj_file = mkdir(new_dir+"/repeat_"+str(repeat)+"/") + str(outputFileParentName)+"_"+str(num_consumers)+"_objs"
    write_objs([one.objectives for one in pf], obj_file)