# Warm starting Xpress with a full basis using JuMP

**URL:** https://discourse.julialang.org/t/warm-starting-xpress-with-a-full-basis-using-jump/96216
**Category:** Optimization (Mathematical)
**Tags:** question, jump
**Created:** [March 16, 2023, 11:23pm UTC](https://discourse.julialang.org/t/warm-starting-xpress-with-a-full-basis-using-jump/96216 "2023-03-16T23:23:16Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Diego](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Diego](https://discourse.julialang.org/u/Diego)
#### Post date: [March 16, 2023, 11:23pm UTC](https://discourse.julialang.org/t/warm-starting-xpress-with-a-full-basis-using-jump/96216/1 "2023-03-16T23:23:16Z")

</div>

Dear all,

I have tried setting initial values/duals of similar problems in JuMP/Xpress for LP problems but we have not been very successful for LP, for MIP we have been though.

I was wondering whether Xpress.writebasis and Xpress.readbasisfrom Xpress would be of any help. What I see, however, is that these functions are only available when the model is built directly from Xpress.jl without JuMP.

Is there a way of using these Xpress.jl functions in a problem built using JuMP?

Thank you!

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [March 16, 2023, 11:37pm UTC](https://discourse.julialang.org/t/warm-starting-xpress-with-a-full-basis-using-jump/96216/2 "2023-03-16T23:37:14Z")

</div>

> [@Diego](#):
>
> Is there a way of using these Xpress.jl functions in a problem built using JuMP?

Not easily.

But if you use `direct_model`, [Models · JuMP](https://jump.dev/JuMP.jl/stable/manual/models/#Direct-mode), then `backend(model)` is the Xpress optimizer, on which you can use the Xpress C API calls.

---

<div class="post-metadata">

### Author: ![Diego](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Diego](https://discourse.julialang.org/u/Diego)
#### Post date: [March 17, 2023, 11:28am UTC](https://discourse.julialang.org/t/warm-starting-xpress-with-a-full-basis-using-jump/96216/3 "2023-03-17T11:28:29Z")

</div>

Some guidance would be ultra useful here, I have honestly tried everything regarding set\_start\_value but unluckily have not had any success, even loading the values generated by the same exact model does not lead to any savings in time with Xpress…

It seems that what is needed is the Xpress problem and not the Xpress Optimizer object, see:

int XPRS\_CC XPRSwritebasis (XPRSprob prob, const char \*\_sfilename, const char \*\_sflags);

I have tried using direct\_model on a small reproducible example, but it seems I am stuck in the same place as before, how would you read and write a basis using a model created with direct\_model?

Thanks

* * *

using JuMP  
using Xpress

model = direct\_model(Xpress.Optimizer());

@variable(model, x[1:2]);  
@constraint(model, x[1] + x[2] \<= 2)  
@variable(model, FO \>= 0)  
@constraint(model, objfun, FO == 2 \* x[1] + x[2] )  
@objective(model, Min, FO)

optimize!(model)

Xpress.writebasis(backend(model),“basis.bas”, “”)

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [March 17, 2023, 10:04pm UTC](https://discourse.julialang.org/t/warm-starting-xpress-with-a-full-basis-using-jump/96216/4 "2023-03-17T22:04:49Z")

</div>

I don’t have Xpress installed, so I can’t test, but you probably need something like this:

```plaintext
using JuMP
using Xpress
model = direct_model(Xpress.Optimizer());
@variable(model, x[1:2]);
@constraint(model, x[1] + x[2] <= 2)
@variable(model, FO >= 0)
@constraint(model, objfun, FO == 2 * x[1] + x[2] )
@objective(model, Min, FO)
optimize!(model)
b = backend(model)
Xpress.writebasis(b.inner, "basis.bas", "")

```

Using the C API of the solver is largely undocumented and requires advanced knowledge of the C APIs. (It’s also too easy to make a mistake when using them, see, e.g., [https://discourse.julialang.org/t/slow-model-construction-in-jump/95455.](https://discourse.julialang.org/t/slow-model-construction-in-jump/95455.))

Your best bet is reading the source code to see how the MOI wrapper calls things: [Xpress.jl/src/MOI at master · jump-dev/Xpress.jl · GitHub](https://github.com/jump-dev/Xpress.jl/tree/master/src/MOI).

The internal Xpress C wrapper is also a bit rough. Work is currently underway to improve things: [use Lib. directly by joaquimg · Pull Request #194 · jump-dev/Xpress.jl · GitHub](https://github.com/jump-dev/Xpress.jl/pull/194).

---

<div class="post-metadata">

### Author: ![Diego](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Diego](https://discourse.julialang.org/u/Diego)
#### Post date: [March 18, 2023, 5:14pm UTC](https://discourse.julialang.org/t/warm-starting-xpress-with-a-full-basis-using-jump/96216/5 "2023-03-18T17:14:46Z")

</div>

Thank you,

with what you shared I have been able to create and read a basis from disk. However, I have been unable to properly load it as (it seems) the basis is stored without providing a name so it is unable to locate in the model the columns stored, see:

```
    ?131 Warning: No column: C1
    ?131 Warning: No column: C2
    ?131 Warning: No column: C3

```

How should I overcome this limitation?

Thank you

D

* * *

using JuMP  
using Xpress

function create\_optimization\_problem()  
model = direct\_model(Xpress.Optimizer());  
@variable(model, x \>= 0, Int)  
@variable(model, y \>= 0, Int)  
@variable(model, FO \>= 0)  
@constraint(model, c1, 10_x + 20_y \<= 220 )  
@constraint(model, c2, 11_x + 19_y \<= 220 )  
@constraint(model, c3, 12_x + 18_y \<= 220 )  
@constraint(model, c4, 13_x + 17_y \<= 220 )  
@constraint(model, c5, 14_x + 16_y \<= 220 )  
@constraint(model, c6, 15_x + 15_y \<= 220 )  
@constraint(model, c7, 16_x + 14_y \<= 220 )  
@constraint(model, c8, 17_x + 13_y \<= 220 )  
@constraint(model, c9, 18_x + 12_y \<= 220 )  
@constraint(model, c10, 19_x + 11_y \<= 220 )  
@constraint(model, c11, 20_x + 10_y \<= 220 )  
@constraint(model, c12, FO == x + y )  
@objective(model, Max, FO)  
return model  
end

model = create\_optimization\_problem()

@time optimize!(model)

Xpress.writebasis(backend(model).inner, “basis.bas”, “”)

model = create\_optimization\_problem()

Xpress.readbasis(backend(model).inner, “basis.bas”, “”)

@time optimize!(model)

---

<div class="post-metadata">

### Author: ![Diego](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Diego](https://discourse.julialang.org/u/Diego)
#### Post date: [March 18, 2023, 5:29pm UTC](https://discourse.julialang.org/t/warm-starting-xpress-with-a-full-basis-using-jump/96216/6 "2023-03-18T17:29:25Z")

</div>

The issue seems to be related with the lack of proving the variable and constraint names to Xpress, I have tried with set\_optimizer\_attributes(model, “LOADNAMES” =\> true) but this function does not seem to be available.

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [March 19, 2023, 8:40pm UTC](https://discourse.julialang.org/t/warm-starting-xpress-with-a-full-basis-using-jump/96216/7 "2023-03-19T20:40:53Z")

</div>

The low-level C APIs for each solver are accessible, but (by design) they aren’t set up so things work smoothly.

I don’t know the details, but it seems like Xpress.jl currently doesn’t pass the names to the inner model: [add variable and constraint name by viniciusjusten · Pull Request #193 · jump-dev/Xpress.jl · GitHub](https://github.com/jump-dev/Xpress.jl/pull/193).

So if you want this, you’ll likely need to manually call other C API methods.
