File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ function QuadraticModel(
48
48
lvar:: S = fill! (S (undef, length (c)), eltype (c)(- Inf )),
49
49
uvar:: S = fill! (S (undef, length (c)), eltype (c)(Inf )),
50
50
c0:: T = zero (eltype (c)),
51
+ sortcols:: Bool = false ,
51
52
kwargs... ,
52
53
) where {T, S}
53
54
nnzh = length (Hvals)
@@ -66,6 +67,16 @@ function QuadraticModel(
66
67
if ! (nvar == length (lvar) == length (uvar))
67
68
error (" The length of c, lvar and uvar must be the same" )
68
69
end
70
+ if sortcols
71
+ pH = sortperm (Hcols)
72
+ permute! (Hrows, pH)
73
+ permute! (Hcols, pH)
74
+ permute! (Hvals, pH)
75
+ pA = sortperm (Acols)
76
+ permute! (Arows, pA)
77
+ permute! (Acols, pA)
78
+ permute! (Avals, pA)
79
+ end
69
80
QuadraticModel (
70
81
NLPModelMeta (
71
82
length (c),
Original file line number Diff line number Diff line change 72
72
testSM (qp)
73
73
end
74
74
75
+ @testset " sort cols COO" begin
76
+ Hrows = [1 ; 2 ; 1 ; 3 ]
77
+ Hcols = [2 ; 1 ; 4 ; 4 ]
78
+ Hvals = [1.0 ; 2.0 ; 3.0 ; 4.0 ]
79
+ Arows = [2 ; 2 ; 1 ; 4 ]
80
+ Acols = [4 ; 3 ; 1 ; 2 ]
81
+ Avals = [- 1.0 ; - 2.0 ; - 3.0 ; - 4.0 ]
82
+ c = [- 8.0 ; - 3 ; - 3 ; 2.0 ]
83
+ l = [0.0 ; 0 ; 0 ; 0 ]
84
+ u = [Inf ; Inf ; Inf ; Inf ]
85
+ qp = QuadraticModel (
86
+ c,
87
+ Hrows,
88
+ Hcols,
89
+ Hvals,
90
+ Arows = Arows,
91
+ Acols = Acols,
92
+ Avals = Avals,
93
+ lcon = [- 3.0 ; - 4.0 ; 2.0 ; 1.0 ],
94
+ ucon = [- 2.0 ; Inf ; Inf ; Inf ],
95
+ lvar = l,
96
+ uvar = u,
97
+ c0 = 0.0 ,
98
+ name = " QM1" ,
99
+ sortcols = true ,
100
+ )
101
+ @test issorted (Hcols)
102
+ @test issorted (Acols)
103
+ end
104
+
75
105
include (" test_presolve.jl" )
You can’t perform that action at this time.
0 commit comments