Error when supplying initial guess

If I set my variable to be lower trianglar, how can I supply an initial guess? The following gives me an error that has to do with the difference in the data type between the variable X and the initial guess X0

using JuMP
using LinearAlgebra
n = 4
model = Model()
@variable(model, X[1:n, 1:n], Symmetric)
X = LowerTriangular(X)
X0 = ones(n,n)
# Xl0 = LowerTriangular(X0)
set_start_value.(X, X0)
# set_start_value.(X, Xl0)

MethodError: no method matching set_start_value(::AffExpr, ::Float64)
Closest candidates are:
set_start_value(::ConstraintRef{<:AbstractModel, <:MathOptInterface.ConstraintIndex{<:MathOptInterface.AbstractVectorFunction, <:MathOptInterface.AbstractVectorSet}}, ::Any) at ~/.julia/packages/JuMP/60Bnj/src/constraints.jl:141
set_start_value(::ConstraintRef{<:AbstractModel, <:MathOptInterface.ConstraintIndex{<:MathOptInterface.AbstractScalarFunction, <:MathOptInterface.AbstractScalarSet}}, ::Any) at ~/.julia/packages/JuMP/60Bnj/src/constraints.jl:168
set_start_value(::VariableRef, ::Union{Nothing, Float64}) at ~/.julia/packages/JuMP/60Bnj/src/variables.jl:1015

1 Like

This is a problem broadcasting over a LowerTriangular matrix. A lot of the rules in Julia’s LinearAlgebra submodule don’t play nicely with JuMP.

Do:

using JuMP
using LinearAlgebra
n = 4
model = Model()
@variable(model, X[1:n, 1:n], Symmetric, start = 1)

or

using JuMP
using LinearAlgebra
n = 4
model = Model()
@variable(model, X[1:n, 1:n], Symmetric)
X0 = ones(n,n)
set_start_value.(X, X0)
Xl = LowerTriangular(X)

@odow Actually this did does not work. For some reason, if you check the initial value for the variable Xl by typing

start_value.(Xl)

or

start_value(Xl[1,1])

and

start_value(Xl[1,2])

, you will see that only the diagonal elements of of X0 are stored as starting values, and the rest of the elements of Xl do not store the starting value!! It’s weird.

Is there any other way to store this starting value with this lower triangular matrix formulation?

Actually this did does not work

It works for me. Can you show an example where it doesn’t?

start_value(Xl[1,2])

This value doesn’t exist because it refers to the upper triangular component. You need instead Xl[2, 1].

@odow Yes you are right. It worked in the original example but here is an example where it failed.

using LinearAlgebra
using JuMP

model = Model()
A0 = [0.8838690285718926 0.0 0.0 0.0 0.0 0.0; -0.008316152744522753 0.121162277532093 0.0 0.0 0.0 0.0; -0.28631572272021377 0.9037570584321651 0.2690998746247849 0.0 0.0 0.0; 0.0246261554790738 0.349183281792961 0.0022806121676061416 0.12469557341957281 0.0 0.0; 4.152455739766909 5.31344761542315 1.6323392598339788 -10.168089383216701 -0.09688778288749404 0.0; -687.1727963778304 -106.0785112003266 -253.33763817980469 -217.40093361126466 1264.761769244352 0.11405506253479718];
n = 6
@variable(model, A[1:n, 1:n] , Symmetric)
set_start_value.(A, A0)
start_value.(A)
Al = LowerTriangular(A)
start_value(Al[2,1])

I think it does NOT have to do with the Lower triangular structure since the error appears before. I am still not sure why it only takes the diagonal elements of A0

Ah. I misunderstood your question. The issue is that JuMP represents the symmetric matrix as upper triangular, and your A0 is lower triangular. Do set_start_value.(A, A0').

@odow Yes it worked now! Thank you so much for the help