# How to feed initial solution to solver?

I am keen to learn how to feed an initial solution to a solver. I use the following example and I got the above warning when I used CPLEX, Cbc, Gurobi, GLPK. Could any one point me in the right direction to solve this issue or is there any solver that accepts an initial solution?

using JuMP
using MathOptInterface
using Gurobi
using CPLEX
using GLPK
using Cbc
function solveModel(solver)
myModel=Model(with_optimizer(solver.Optimizer))
@variable(myModel, x, Int)
@variable(myModel, y, Int)
@variable(myModel, z>=0)
@variable(myModel, e[1:3], Bin)
@constraint(myModel,con1, 2x+3y<=10)
@constraint(myModel,con2, 3x+2y<=12)
@constraint(myModel,con3, z==2x+4y)
@constraint(myModel,con4, x>=y)
@constraint(myModel, con5, sum(e)==1)
@objective(myModel, Max,z)
vars=all_variables(myModel)
vals=[2,2,12,1,0,0]
set_start_value.(vars,vals)
optimize!(myModel)
@show termination_status(myModel) == MathOptInterface.OPTIMAL
@show primal_status(myModel) == MathOptInterface.FEASIBLE_POINT
has_values(myModel)
sol=value.(vars)
return myModel, sol
end

I get the following output when I use GLPK. I have commented out â€śvalsâ€ť and â€śset_start_valueâ€ť. This looks fine.

``````(A JuMP Model
Maximization problem with:
Variables: 6
Objective function type: VariableRef
`VariableRef`-in-`MathOptInterface.ZeroOne`: 3 constraints
`VariableRef`-in-`MathOptInterface.Integer`: 2 constraints
`VariableRef`-in-`MathOptInterface.GreaterThan{Float64}`: 1 constraint
`GenericAffExpr{Float64,VariableRef}`-in-`MathOptInterface.EqualTo{Float64}`: 2 constraints
`GenericAffExpr{Float64,VariableRef}`-in-`MathOptInterface.GreaterThan{Float64}`: 1 constraint
`GenericAffExpr{Float64,VariableRef}`-in-`MathOptInterface.LessThan{Float64}`: 2 constraints
Model mode: AUTOMATIC
CachingOptimizer state: ATTACHED_OPTIMIZER
Solver name: GLPK
Names registered in the model: con1, con2, con3, con4, con5, e, x, y, z, [2.0, 2.0, 12.0, 1.0, 0.0, 0.0])
``````

This is a duplicate of Warning, invalid warm-start basis discarded so Iâ€™m closing this thread.

1 Like