Пример #1
0
def column_generation_loop(args, inst, cg):
    continue_cond = True

    if args.dump:
        cg.write_suffix("first_solve")

    res = cg.solve()
    first_obj = res.obj
    best_int_obj = first_obj

    stab = CG.Stabilization(inst, args)

    alpha = stab.alpha0()

    loop_start = time()
    while continue_cond:
        rtime = 0
        line(1)

        r_start = time()
        if args.dump:
            cg.write_suffix(stab.iterations())

        res = cg.solve()
        if args.dump:
            cg.writesol(stab.iterations())
        rtime += res.rtime
        r_stop = time()

        msg(1,
            "%5d master %20.3f %20.3f %8.3f (%8.3f)   %.6f %20.3f %s" %
            (stab.iterations(), res.obj, first_obj, r_stop - r_start,
             res.rtime, alpha, res.obj - first_obj, res.allint),
            timeref=loop_start)

        if res is None:
            raise Exception("LP não ótimo")

        rtime += res.rtime

        stduals = stab.alpha(res)
        omega = 0
        add_col = False
        for m in inst.M:
            c_start = time()

            sigma = stduals.eta_lb[:, m] + stduals.eta_ub[:, inst.iN[
                m]] + stduals.omikron_lb[:, m] + stduals.omikron_ub[:,
                                                                    inst.iL[m]]

            cg.column_prepare(machine=m,
                              pi=stduals.pi,
                              gamma=stduals.gamma,
                              sigma=sigma,
                              mu=stduals.mu[m])
            if args.dump:
                cg.column_write(machine=m, k=k)

            cres = cg.column_compute(machine=m)

            if args.validate:
                vres = cg.column_validate(cres,
                                          machine=m,
                                          pi=stduals.pi,
                                          gamma=stduals.gamma,
                                          sigma=sigma,
                                          mu=stduals.mu[m])

                if vres.status != CG.CGValidateStatus.Valid:
                    print(vres)
                    raise Exception("problema ao validar coluna")

            omega += cres.rc
            rtime += cres.rtime

            ares = cg.lp_add_col(m, cres)

            if ares.status == CG.CGAddStatus.Added:
                add_col = True
            elif ares.status == CG.CGAddStatus.NotAdded:
                print(ares)
                raise Exception("problema ao adicionar coluna")

            c_stop = time()
            msg(3,
                "%5d  %5d %20.3f %20.3f %8.3f (%8.3f) %s" %
                (stab.iterations(), m, cres.rc, cres.obj, c_stop - c_start,
                 cres.rtime, ares.status.value),
                timeref=loop_start)

        if omega > -args.epslon or not add_col:
            continue_cond = False
        if stab.iterations() == args.maxsteps:
            continue_cond = False

        msg(1,
            "%5d  omega %20.3f %20.3f %8.3f (%8.3f)   %0.6f %5d %5d %8.3f %s" %
            (stab.iterations(), omega, stab.best_omega(),
             time() - r_start, rtime, alpha, stab.improvements(),
             stab.nonimprovements(), omega / stab.best_omega(), continue_cond),
            timeref=loop_start)

        alpha = stab.compute(omega=omega, stabdual=stduals)
Пример #2
0
                                   a=None,
                                   d=None,
                                   b=None,
                                   pmc=None,
                                   mmc=None,
                                   rtime=None)

                cg.lp_add_col(m, cres)
            m_assign[p] = not m_assign[p]

continue_cond = True

res = cg.solve_relax()
first_obj = res.obj

stab = CG.Stabilization(inst, args)

alpha = stab.alpha0()

k = 0
loop_start = time()
while continue_cond:
    rtime = 0
    if args.verbose > 1:
        print("-" * (int(columns) - 2))
        if args.time:
            print("%12.3f %12.3f " % (time() - all_start, time() - loop_start),
                  end='')
        print("%5d master" % (k), end=' ')

    r_start = time()