Exemplo n.º 1
0
def SolveProblem(problem, constructive=True, aco=True, Model=False):
    nt = len([(v, i) for v in range(1, problem.numVertices)
              for i in range(problem.numTasks[problem.request[v]])])

    print('num tasks', nt)
    if constructive:
        ts = time.time()
        sol = Constructive.Constructive(problem)
        te = time.time()
        print('Constructive heuristic')
        print('  Solution:', len(sol), 'days')
        print('  Time:', te - ts)

    if aco:
        ts = time.time()
        sol = ACO.Main.Solve(problem)
        te = time.time()
        print('Ant Colony Algorithm')
        print('  Solution:', len(sol), 'days')
        print('  Time:', te - ts)

    if Model:
        print('Model')

        info, _ = Model2.Solve(problem, sol, integer=False)
        lbroot = info['lb']

        ts = time.time()
        info, sol = Model2.Solve(problem, sol, integer=True)
        te = time.time()

        print('  Upper bound:', info['ub'])
        if info['status'] == 'MIP_optimal':
            print('  Lower bound:', info['ub'])
        else:
            print('  Lower bound:', info['lb'])

        print('  Root lower bound:', lbroot)
        print('  Root lower bound (with cplex cuts):', info['lbroot'])
        print('  Number of nodes:', info['numnodes'])
        print('  Time', te - ts)