Skip to content

Commit cae2e41

Browse files
committed
try allowing rows >= columns
1 parent 04e4c91 commit cae2e41

File tree

2 files changed

+120
-5
lines changed

2 files changed

+120
-5
lines changed

src/Bridges/Constraint/norm_spec_nuc_to_psd.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ function bridge_constraint(::Type{NormSpectralBridge{T, F, G}}, model::MOI.Model
1414
t = f_scalars[1]
1515
row_dim = s.row_dim
1616
column_dim = s.column_dim
17-
@assert row_dim <= column_dim
1817
side_dim = row_dim + column_dim
1918
psd_set = MOI.PositiveSemidefiniteConeTriangle(side_dim)
2019
psd_func = MOIU.zero_with_output_dimension(F, MOI.dimension(psd_set))
@@ -90,7 +89,6 @@ function bridge_constraint(::Type{NormNuclearBridge{T, F, G, H}}, model::MOI.Mod
9089
f_scalars = MOIU.eachscalar(f)
9190
row_dim = s.row_dim
9291
column_dim = s.column_dim
93-
@assert row_dim <= column_dim
9492
side_dim = row_dim + column_dim
9593
U_dim = div(column_dim * (column_dim + 1), 2)
9694
V_dim = div(row_dim * (row_dim + 1), 2)

src/Test/contconic.jl

Lines changed: 120 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1950,7 +1950,65 @@ function normspec1test(model::MOI.ModelLike, config::TestConfig)
19501950
end
19511951
end
19521952

1953-
normspectests = Dict("normspec1" => normspec1test)
1953+
function normspec2test(model::MOI.ModelLike, config::TestConfig)
1954+
atol = config.atol
1955+
rtol = config.rtol
1956+
# Problem NormSpec2
1957+
# min t
1958+
# st t >= sigma_1([1 1; 1 -1; 0 1]) (i.e (t, 1, 1, 0, 1, -1, 1]) is in NormSpectralCone(3, 2))
1959+
# Singular values are [sqrt(3), sqrt(2)], so optimal solution is:
1960+
# t = sqrt(3)
1961+
1962+
@test MOIU.supports_default_copy_to(model, #=copy_names=# false)
1963+
@test MOI.supports(model, MOI.ObjectiveFunction{MOI.SingleVariable}())
1964+
@test MOI.supports(model, MOI.ObjectiveSense())
1965+
@test MOI.supports_constraint(model, MOI.VectorAffineFunction{Float64}, MOI.NormSpectralCone)
1966+
1967+
MOI.empty!(model)
1968+
@test MOI.is_empty(model)
1969+
1970+
t = MOI.add_variable(model)
1971+
@test MOI.get(model, MOI.NumberOfVariables()) == 1
1972+
1973+
data = Float64[1, 1, 0, 1, -1, 1]
1974+
spec = MOI.add_constraint(model, MOI.VectorAffineFunction([MOI.VectorAffineTerm(1, MOI.ScalarAffineTerm(1.0, t))], vcat(0.0, data)), MOI.NormSpectralCone(3, 2))
1975+
1976+
MOI.set(model, MOI.ObjectiveFunction{MOI.SingleVariable}(), MOI.SingleVariable(t))
1977+
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
1978+
1979+
if config.solve
1980+
@test MOI.get(model, MOI.TerminationStatus()) == MOI.OPTIMIZE_NOT_CALLED
1981+
1982+
MOI.optimize!(model)
1983+
1984+
@test MOI.get(model, MOI.TerminationStatus()) == config.optimal_status
1985+
1986+
@test MOI.get(model, MOI.PrimalStatus()) == MOI.FEASIBLE_POINT
1987+
if config.duals
1988+
@test MOI.get(model, MOI.DualStatus()) == MOI.FEASIBLE_POINT
1989+
end
1990+
1991+
rt3 = sqrt(3)
1992+
@test MOI.get(model, MOI.ObjectiveValue()) rt3 atol=atol rtol=rtol
1993+
if config.dual_objective_value
1994+
@test MOI.get(model, MOI.DualObjectiveValue()) rt3 atol=atol rtol=rtol
1995+
end
1996+
1997+
@test MOI.get(model, MOI.VariablePrimal(), t) rt3 atol=atol rtol=rtol
1998+
@test MOI.get(model, MOI.ConstraintPrimal(), spec) vcat(rt3, data) atol=atol rtol=rtol
1999+
2000+
if config.duals
2001+
invrt3 = inv(rt3)
2002+
@test MOI.get(model, MOI.ConstraintDual(), spec) Float64[1, 0, invrt3, -invrt3, 0, 0, -invrt3] atol=atol rtol=rtol
2003+
end
2004+
end
2005+
end
2006+
2007+
2008+
normspectests = Dict(
2009+
"normspec1" => normspec1test,
2010+
"normspec2" => normspec2test,
2011+
)
19542012

19552013
@moitestset normspec
19562014

@@ -2001,18 +2059,77 @@ function normnuc1test(model::MOI.ModelLike, config::TestConfig)
20012059
end
20022060

20032061
@test MOI.get(model, MOI.VariablePrimal(), t) rt3 + rt2 atol=atol rtol=rtol
2004-
@test MOI.get(model, MOI.ConstraintPrimal(), nuc) Float64[rt2 + rt3, 1, 1, 1, -1, 0, 1] atol=atol rtol=rtol
2062+
@test MOI.get(model, MOI.ConstraintPrimal(), nuc) vcat(rt3 + rt2, data) atol=atol rtol=rtol
20052063

20062064
if config.duals
20072065
invrt2 = inv(rt2)
20082066
invrt3 = inv(rt3)
20092067
@test MOI.get(model, MOI.ConstraintDual(), nuc) Float64[1, -invrt2, -invrt3, -invrt2, invrt3, 0, -invrt3] atol=atol rtol=rtol
2068+
end
2069+
end
2070+
end
20102071

2072+
function normnuc2test(model::MOI.ModelLike, config::TestConfig)
2073+
atol = config.atol
2074+
rtol = config.rtol
2075+
# Problem NormNuc2
2076+
# min t
2077+
# st t >= sum_i sigma_i([1 1; 1 -1; 0 1]) (i.e (t, 1, 1, 0, 1, -1, 1]) is in NormNuclearCone(3, 2))
2078+
# Singular values are [sqrt(3), sqrt(2)], so optimal solution is:
2079+
# t = sqrt(3) + sqrt(2)
2080+
2081+
@test MOIU.supports_default_copy_to(model, #=copy_names=# false)
2082+
@test MOI.supports(model, MOI.ObjectiveFunction{MOI.SingleVariable}())
2083+
@test MOI.supports(model, MOI.ObjectiveSense())
2084+
@test MOI.supports_constraint(model, MOI.VectorAffineFunction{Float64}, MOI.NormNuclearCone)
2085+
2086+
MOI.empty!(model)
2087+
@test MOI.is_empty(model)
2088+
2089+
t = MOI.add_variable(model)
2090+
@test MOI.get(model, MOI.NumberOfVariables()) == 1
2091+
2092+
data = Float64[1, 1, 0, 1, -1, 1]
2093+
nuc = MOI.add_constraint(model, MOI.VectorAffineFunction([MOI.VectorAffineTerm(1, MOI.ScalarAffineTerm(1.0, t))], vcat(0.0, data)), MOI.NormNuclearCone(3, 2))
2094+
2095+
MOI.set(model, MOI.ObjectiveFunction{MOI.SingleVariable}(), MOI.SingleVariable(t))
2096+
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
2097+
2098+
if config.solve
2099+
@test MOI.get(model, MOI.TerminationStatus()) == MOI.OPTIMIZE_NOT_CALLED
2100+
2101+
MOI.optimize!(model)
2102+
2103+
@test MOI.get(model, MOI.TerminationStatus()) == config.optimal_status
2104+
2105+
@test MOI.get(model, MOI.PrimalStatus()) == MOI.FEASIBLE_POINT
2106+
if config.duals
2107+
@test MOI.get(model, MOI.DualStatus()) == MOI.FEASIBLE_POINT
2108+
end
2109+
2110+
rt3 = sqrt(3)
2111+
rt2 = sqrt(2)
2112+
@test MOI.get(model, MOI.ObjectiveValue()) rt3 + rt2 atol=atol rtol=rtol
2113+
if config.dual_objective_value
2114+
@test MOI.get(model, MOI.DualObjectiveValue()) rt3 + rt2 atol=atol rtol=rtol
2115+
end
2116+
2117+
@test MOI.get(model, MOI.VariablePrimal(), t) rt3 + rt2 atol=atol rtol=rtol
2118+
@test MOI.get(model, MOI.ConstraintPrimal(), nuc) vcat(rt3 + rt2, data) atol=atol rtol=rtol
2119+
2120+
if config.duals
2121+
invrt2 = inv(rt2)
2122+
invrt3 = inv(rt3)
2123+
@test MOI.get(model, MOI.ConstraintDual(), nuc) Float64[1, -invrt2, invrt3, -invrt3, 0, -invrt2, -invrt3] atol=atol rtol=rtol
20112124
end
20122125
end
20132126
end
20142127

2015-
normnuctests = Dict("normnuc1" => normnuc1test)
2128+
2129+
normnuctests = Dict(
2130+
"normnuc1" => normnuc1test,
2131+
"normnuc2" => normnuc2test,
2132+
)
20162133

20172134
@moitestset normnuc
20182135

0 commit comments

Comments
 (0)