-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path#Ipopt_Sparse.jl
38 lines (29 loc) · 970 Bytes
/
#Ipopt_Sparse.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using JuMP, Ipopt, MatrixDepot, SparseArrays
# Download the sparse matrix
sparse_matrix = matrixdepot("sparse/your_matrix_name", SparseMatrixCSC)
# Define the problem dimensions
m, n = size(sparse_matrix)
# Create random data for the linear program
c = rand(n)
b = sparse_matrix * rand(n)
# Create a JuMP model using the Ipopt solver
model = Model(Ipopt.Optimizer)
# Create decision variables
@variable(model, x[1:n] >= 0)
# Create the objective function
@objective(model, Min, dot(c, x))
# Add the constraints
for i in 1:m
@constraint(model, dot(sparse_matrix[i, :], x) == b[i])
end
# Solve the linear program
optimize!(model)
# Check the solution status
status = termination_status(model)
if status == MOI.OPTIMAL
println("Optimal solution found")
println("Objective value: ", objective_value(model))
println("Solution vector: ", value.(x))
else
println("Solver terminated with status: ", status)
end