Skip to content
This repository has been archived by the owner on Aug 11, 2019. It is now read-only.

4 Sub Problem

edxu96 edited this page May 27, 2019 · 2 revisions

1, Functions in FuncSub.jl

All the data for sub-problem is stored in the mutable struct ModelSub:

mutable struct ModelSub
    mod::JuMP.Model
    mat_e
    vec_l
    mat_d
    vec_q
    vec_x
    vecSense
end

Function setModelSub then is used to generate all the needed sub-problems:

function setModelSub(mat_a, vec_b, vec_c, vecSense, indexMas, blocks, indexSub, gurobi_env, whiSolver)
    numSub = length(blocks)
    vecModelSub = Vector{ModelSub}(undef, numSub)
    if whiSolver == 1
        modWhiSolver = Model(solver = GurobiSolver(OutputFlag = 0, gurobi_env))
    elseif whiSolver == 2
        modWhiSolver = Model(solver = CplexSolver(CPX_PARAM_SCRIND=0))
    else
        modWhiSolver = Model(solver = GLPKSolverLP())
    end
    for k = 1:numSub
        vecModelSub[k] = ModelSub(
            modWhiSolver,                                                 # mod
            deepcopy(mat_a[collect(indexMas), indexSub[k]]),              # mat_e
            deepcopy(vec_c[indexSub[k]]),                                 # vec_l
            deepcopy(mat_a[blocks[k], indexSub[k]]),                      # mat_d
            deepcopy(vec_b[blocks[k]]),                                   # vec_q
            0,                                                            # vec_x
            deepcopy(vecSense[blocks[k]])                                 # vecSense
            )
    end
    # vecModelSub = setBranch(vecModelSub, 1, 2)
    for k = 1:numSub
        vecModelSub[k].vec_x = setVariableSub(vecModelSub[k].mod, vecModelSub[k].mat_d, vecModelSub[k].vec_q,
            vecModelSub[k].vecSense)
    end
    return vecModelSub
end

2, How to Use

vecModelSub = setModelSub(mat_a, vec_b, vec_c, vecSenseAll, indexMas, blocks, indexSub, gurobi_env, whiSolver)

Every iteration

## Dantzig Wolfe Column Generation
costReduceBest = -1
for k = 1:numSub
    (costReduce, vec_x_result) = solveSub(vecModelSub[k], vecPi, vecKappa[k])
    if whePrint
        println("Reduced cost of $(k)-th sub model is $costReduce.")
    end
    if costReduce > costReduceBest
        costReduceBest = costReduce
    end
    # remember to look for negative reduced cost if we are minimizing.
    if costReduce > epsilon
        (lambdaNew, objCoefNew) = addColToMas(modMas, vecModelSub[k], vec_x_result,
            vecConsRef, vecConsConvex[k])
        push!(vecLambda, lambdaNew)
        push!(vecObjCoef, objCoefNew)
        push!(extremePoints, vec_x_result)
        push!(extremePointForSub, k)
        wheDoneColGen = false
    end
end
Clone this wiki locally