Quantcast

Modifying constraint references within function

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Modifying constraint references within function

Jesse Jaanila
Hi,

I have a column generation scheme where at each iteration I add a new column that has coefficients for several hundred
constraints that I have references pointed at. i.e.

for row = 1:M
 my_cons[row] = @constraint(m,.....)
end

I have a new empty array of constraint references built with @constrainf new_col[1:some_integer] that contains space for a subset of references I need.
I try to modify this array of constraints references within a function with type ::Array{JuMP.ConstraintRef{M<:JuMP.AbstractModel,T<:JuMP.AbstractConstraint},1},
but I get an error:

ERROR: LoadError: LoadError: unsupported or misplaced expression <:

What is the type of @constraintref array when passed into a function, can the content be modified within the function and does the references have to be sorted in some way (increasing row reference?).

--
You received this message because you are subscribed to the Google Groups "julia-opt" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
Visit this group at https://groups.google.com/group/julia-opt.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Modifying constraint references within function

Joey Huchette-2

Impossible to say without more code, but the error suggests that what you have written is not valid julia code. If you’re using ::Array{JuMP.ConstraintRef{M<:JuMP.AbstractModel,T<:JuMP.AbstractConstraint},1} as some form of type assertion, that would be the problem. To check the type of the array, use typeof.

-Joey


On Mon, Oct 17, 2016 at 5:04 AM, Jesse Jaanila <[hidden email]> wrote:
Hi,

I have a column generation scheme where at each iteration I add a new column that has coefficients for several hundred
constraints that I have references pointed at. i.e.

for row = 1:M
 my_cons[row] = @constraint(m,.....)
end

I have a new empty array of constraint references built with @constrainf new_col[1:some_integer] that contains space for a subset of references I need.
I try to modify this array of constraints references within a function with type ::Array{JuMP.ConstraintRef{M<:JuMP.AbstractModel,T<:JuMP.AbstractConstraint},1},
but I get an error:

ERROR: LoadError: LoadError: unsupported or misplaced expression <:

What is the type of @constraintref array when passed into a function, can the content be modified within the function and does the references have to be sorted in some way (increasing row reference?).

--
You received this message because you are subscribed to the Google Groups "julia-opt" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
Visit this group at https://groups.google.com/group/julia-opt.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "julia-opt" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
Visit this group at https://groups.google.com/group/julia-opt.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Modifying constraint references within function

Jesse Jaanila
Yes I usedArray{JuMP.ConstraintRef{M<:JuMP.AbstractModel,T<:JuMP.AbstractConstraint},1} which is what typeof() return to me. What should I use in type assertion if I want to pass something like

@constraintref cons[1:100]

into a function? Also, what is the correct way to handle a situation, where I want to dynamically pass different amount of constraint references to inconstraint= part of the @variable macro. Do I have to reallocate the reference array so that all the elements of it have an unique reference OR can I somehow use a long "master" reference array and when I pass it to @variable I could tell the model that only check the first 5 elements of the array for references (i.e. new variable is added into those 5 constraints)?

If this has not been implemented, It would be a great add-on for people using JuMP for column generation. When I do variable fixing branching, this kind of control would be useful.

On Monday, October 17, 2016 at 4:37:24 PM UTC+3, Joey Huchette wrote:

Impossible to say without more code, but the error suggests that what you have written is not valid julia code. If you’re using ::Array{JuMP.ConstraintRef{M<:JuMP.AbstractModel,T<:JuMP.AbstractConstraint},1} as some form of type assertion, that would be the problem. To check the type of the array, use typeof.

-Joey


On Mon, Oct 17, 2016 at 5:04 AM, Jesse Jaanila <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="PGZznyLpBgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jessej...@...> wrote:
Hi,

I have a column generation scheme where at each iteration I add a new column that has coefficients for several hundred
constraints that I have references pointed at. i.e.

for row = 1:M
 my_cons[row] = @constraint(m,.....)
end

I have a new empty array of constraint references built with @constrainf new_col[1:some_integer] that contains space for a subset of references I need.
I try to modify this array of constraints references within a function with type ::Array{JuMP.ConstraintRef{M<:JuMP.AbstractModel,T<:JuMP.AbstractConstraint},1},
but I get an error:

ERROR: LoadError: LoadError: unsupported or misplaced expression <:

What is the type of @constraintref array when passed into a function, can the content be modified within the function and does the references have to be sorted in some way (increasing row reference?).

--
You received this message because you are subscribed to the Google Groups "julia-opt" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="PGZznyLpBgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">julia-opt+...@googlegroups.com.
Visit this group at <a href="https://groups.google.com/group/julia-opt" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/julia-opt&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/julia-opt&#39;;return true;">https://groups.google.com/group/julia-opt.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "julia-opt" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
Visit this group at https://groups.google.com/group/julia-opt.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Modifying constraint references within function

Joey Huchette-2

What should I use in type assertion if I want to pass something like

@constraintref cons[1:100]

into a function?

Array{JuMP.ConstraintRef,1}.

Also, what is the correct way to handle a situation, where I want to dynamically pass different amount of constraint references to inconstraint= part of the @variable macro. Do I have to reallocate the reference array so that all the elements of it have an unique reference OR can I somehow use a long "master" reference array and when I pass it to @variable I could tell the model that only check the first 5 elements of the array for references (i.e. new variable is added into those 5 constraints)?

This is not currently possible, but I would doubt that this particular allocation will be a bottleneck in your code. If you benchmark your code and find this is in fact a bottleneck, we would certainly consider a PR with the new functionality.

-Joey

--
You received this message because you are subscribed to the Google Groups "julia-opt" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
Visit this group at https://groups.google.com/group/julia-opt.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Modifying constraint references within function

Jesse Jaanila
Thanks!

I'll profile my code and report if it is indeed a problem, but every little things helps and I would argue that adding an argument for how many elements the functions check from values and inconstraint arrays, which when omitted defaults to length(values) == length(inconstraints) wouldn't complex the @variable macro. By the way, does the order which the references are inserted into the constraint array matter or does JuMP or Gurobi some sort of sorting itself.

--
You received this message because you are subscribed to the Google Groups "julia-opt" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
Visit this group at https://groups.google.com/group/julia-opt.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Modifying constraint references within function

Joey Huchette
Ordering doesn't matter, as long as it's consistent across the indices and coefficients. I'm guessing the solver does a sorting and/or reallocation internally anyway, which is why I don't think the reallocation will matter much. 





On Wed, Oct 19, 2016 at 3:46 AM -0400, "Jesse Jaanila" <[hidden email]> wrote:

Thanks!

I'll profile my code and report if it is indeed a problem, but every little things helps and I would argue that adding an argument for how many elements the functions check from values and inconstraint arrays, which when omitted defaults to length(values) == length(inconstraints) wouldn't complex the @variable macro. By the way, does the order which the references are inserted into the constraint array matter or does JuMP or Gurobi some sort of sorting itself.

--
You received this message because you are subscribed to the Google Groups "julia-opt" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
Visit this group at https://groups.google.com/group/julia-opt.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "julia-opt" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
Visit this group at https://groups.google.com/group/julia-opt.
For more options, visit https://groups.google.com/d/optout.
Loading...