# How to feed initial solution to solver?

**URL:** <https://discourse.julialang.org/t/how-to-feed-initial-solution-to-solver/26577>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump\
**Created:** [July 20, 2019, 9:28am UTC](https://discourse.julialang.org/t/how-to-feed-initial-solution-to-solver/26577 "2019-07-20T09:28:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Qun](https://avatars.discourse-cdn.com/v4/letter/q/f1d935/32.png) [@Qun](https://discourse.julialang.org/u/Qun)\
**Post date:** [July 20, 2019, 9:28am UTC](https://discourse.julialang.org/t/how-to-feed-initial-solution-to-solver/26577/1 "2019-07-20T09:28:54Z")

</div>

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?

Many thanks in advance.

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

---

<div class="post-metadata">

**Author:** ![Ajaychat3](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@Ajaychat3](https://discourse.julialang.org/u/Ajaychat3)\
**Post date:** [July 21, 2019, 10:25am UTC](https://discourse.julialang.org/t/how-to-feed-initial-solution-to-solver/26577/2 "2019-07-21T10:25:48Z")

</div>

I get the following output when I use GLPK. I have commented out “vals” and “set\_start\_value”. This looks fine.

```julia
(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])

```

---

<div class="post-metadata">

**Author:** ![miles.lubin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/miles.lubin/32/279_2.png) [@miles.lubin](https://discourse.julialang.org/u/miles.lubin)\
**Post date:** [July 21, 2019, 12:08pm UTC](https://discourse.julialang.org/t/how-to-feed-initial-solution-to-solver/26577/3 "2019-07-21T12:08:20Z")

</div>

This is a duplicate of [Warning, invalid warm-start basis discarded - #4 by Qun](https://discourse.julialang.org/t/warning-invalid-warm-start-basis-discarded/26403/4) so I’m closing this thread.

---

<div class="post-metadata">

**Author:** ![miles.lubin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/miles.lubin/32/279_2.png) [@miles.lubin](https://discourse.julialang.org/u/miles.lubin)\
**Post date:** [July 21, 2019, 12:08pm UTC](https://discourse.julialang.org/t/how-to-feed-initial-solution-to-solver/26577/4 "2019-07-21T12:08:25Z")

</div>


