Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dual variable #14

Closed
mahsap58 opened this issue Jan 31, 2020 · 7 comments
Closed

dual variable #14

mahsap58 opened this issue Jan 31, 2020 · 7 comments

Comments

@mahsap58
Copy link

Hello, I want to get the dual variable of following constraint, I used getdual(con1) but i faced with an error. please help me to get the dual variables of this constraint.
@constraint(model, con1[i = 1:I], sum( x[i,k] * y[k] for k=1:K) == b[i])

@oschulz
Copy link
Owner

oschulz commented Jan 31, 2020

Hello @mahsap58, I'm not quite sure where ValueShapes fits into this. Could you elaborate?

@mahsap58
Copy link
Author

My total code are as below; i have one minimization problem and the second is maximization within a while loop I solve the first, get the dual of it and put it in the second model (i called it c[i], c[i] is the dual variable of constraint of first model), after solving the second model i get the asol and attach it to the x, x is initial solution of the first model. now i need c as the dual variable of first model.
using JuMP
using Gurobi
K=5,I=5
x=[4 0 0 0 0
0 2 0 0 0
0 0 2 0 0
0 0 0 2 0
0 0 0 0 1]
w=[11 15 19 23 27]
b=[97 140 191 85 129]
reducedCost=-Inf
while reducedCost < 0
model = Model(with_optimizer(Gurobi.Optimizer))
@variable(model, 0 <= y[1:K])
@objective(model, Min, sum(y[k] for k = 1:K))
@constraint(model, con1[i = 1:I], sum( x[i,k] * y[k] for k=1:K) == b[i])
optimize!(model)
termination_status(model)
optval = objective_value(model)
ysol = value.(y)
println("Optimal Value = $optval")

@variable(model, 0 <= a[1:I], int)
@objective(model, Max, sum(c[i] * a[i] for i = 1:I))
@constraint(model, con1[i = 1:I], sum( w[i] * a[i] for i=1:I) <= 50)
optimize!(model)
termination_status(model)
reducedCost = objective_value(model)
asol = value.(a)
println("Optimal Value = $optval")
reducedCost=1-reducedCost;
if reducedCost<-0.001;
x = [x,asol];
K=K+1;
end

@oschulz
Copy link
Owner

oschulz commented Jan 31, 2020

@mahsap58, could it be that you posted to the wrong repo? This one is about the ValueShapes package, not JuMP and/or Gurobi.

@mahsap58
Copy link
Author

i tried to install ValueShapes using Pkg.add("ValueShapes") and i think there was an error and it does not installed and this is the error after running the code
Failed to precompile ValueShapes

@oschulz
Copy link
Owner

oschulz commented Jan 31, 2020

Hm, that is strange - I can't reproduce the error, and testing on Travis on Linux, OS-X and Windows also runs fine (see https://travis-ci.com/oschulz/ValueShapes.jl/builds/145010659). Could you try again with a clean, empty Julia environment (empty ".julia" directory)?

@mahsap58
Copy link
Author

what is this error? please tell me how can i install deps.jl
No deps.jl file could be found. Please try running Pkg.build("Arpack").
Currently, the build command might fail when Julia has been built from source
and the recommendation is to use the official binaries from julialang.org.
For more info see JuliaLinearAlgebra/Arpack.jl#5.

@oschulz
Copy link
Owner

oschulz commented Jan 31, 2020

@mahsap58, I get the impression that you're looking for general help on how to use Julia and Julia packages not related to ValueShapes. A better place for that would be https://discourse.julialang.org/ . Could you please direct your questions there?

@oschulz oschulz closed this as completed Jan 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants