Giter Site home page Giter Site logo

disjunctiveprogramming.jl's People

Contributors

github-actions[bot] avatar hdavid16 avatar odow avatar pulsipher avatar shivankj11 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

disjunctiveprogramming.jl's Issues

Clean up code and document

  • Check comments
  • Add docstrings
  • Remove unnecessary args or kwargs
  • Consider cleaning functions by using args... or kwargs...
  • Use Documenter

Big-M for nonlinear constraints

The following lines in the BMR function fail if there is a nonlinear constraint:

    add_to_function_constant(ref, -M)
    bin_var_ref = variable_by_name(ref.model, string(bin_var[i]))
    set_normalized_coefficient(ref, bin_var_ref , M)

What this is doing is adding the Big-M term to the constraint: i.e., M*(1-bin_var_ref).

However, for NL constraints, this needs to be treated as discussed in #7

Code needs to be made more robust

Flexibility in constraint inputs:

  • A disjunct could be a code block (begin...end)
  • A disjunct could be a code block with some or all named constraints
  • A disjunct could be a single constraint
  • A disjunct could be a named constraint
  • A disjunct could be an anonymous constraint
  • the constraint expressions could be defined in the macro itself. Create a disjunction object to extend JuMP.

Constrain splitting:

  • When a constraint set is bounded (i.e. 0<= x <= 1), it needs to be split into two constraints to allow implementing CHR and BMR

Checking variables in a constraint

I hope this helps. You shouldn't need to do the string parsing stuff

using JuMP

function _variable_list(
    list::Set{Int}, 
    nlp::MOI.Nonlinear.Model, 
    expr::MOI.Nonlinear.Expression,
)
    for node in expr.nodes
        if node.type == MOI.Nonlinear.NODE_MOI_VARIABLE
            push!(list, node.index)
        elseif node.type == MOI.Nonlinear.NODE_SUBEXPRESSION
            _variable_list(list, nlp, nlp.expressions[node.index].nodes)
        end
    end
    return
end

function variable_list(c::NonlinearConstraintRef)
    list = Set{Int}()
    nlp = nonlinear_model(c.model)
    constraint = nlp[index(c)]
    _variable_list(list, nlp, constraint.expression)
    return map(sort!(collect(list))) do i
        return VariableRef(c.model, MOI.VariableIndex(i))
    end
end

variable_list(c::ConstraintRef) = variable_list(constraint_object(c).func)

variable_list(c::AffExpr) = collect(keys(c.terms))

model = Model()
@variable(model, x)
@variable(model, y)
@variable(model, z)
c1 = @NLconstraint(model, sin(x) <= z)
c2 = @constraint(model, x + y <= 0)
variable_list(c1)
variable_list(c2)

Upcoming refactoring of JuMP's nonlinear API

The upcoming release of JuMP v1.2 will break DisjunctiveProgramming.jl. Read more here: https://discourse.julialang.org/t/ann-upcoming-refactoring-of-jumps-nonlinear-api/83052

The problem is the use of internal functions and structs here:

#replace original constraint with lb <= func
lb_constr = JuMP._NonlinearConstraint(
JuMP._NonlinearExprData(m, constr_func_expr),
lb,
Inf
)
m.nlp_data.nlconstr[constr.index.value] = lb_constr

Unfortunately, I don't know if we have a safe, publicly documented way of doing this.

x-ref: jump-dev/JuMP.jl#2955

Please ping me if you have questions.

checking proposition expressions fails

this fails:

@proposition(ngdp, ¬(ngdp[Symbol("Y_$i")][1])  ¬(ngdp[Symbol("N_$(i)_$t")][1]))
ERROR: AssertionError: Logical expression does not use valid Boolean symbols: , , ¬, , .

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

Variable Lower Bound

If variables don't have a lower bound and Convex Hull Reformulation is selected, the program will error.
Instead of erroring, the program should assign 0 as the lower bound and give a warning about this.

Need to support multiple disjunctions

Binary variables can be modelled as a Matrix of binaries (2 indices: 1st index is the number of disjuncts, 2nd index is the number of disjunctions). A SparseAxisArray might be better suited for this since not all disjunctions have the same number of disjuncts.

Update code to access a Nonlinear constraint name when supported by JuMP

The following trick is done to get the names of nonlinear constraints (which requires accessing the object dictionary to find the constraint). This is done because name is not supported for Nonlinear constraints (jump-dev/JuMP.jl#3069)

function gen_constraint_name(constr::NonlinearConstraintRef)
constr_name = findfirst(==(constr), constr.model[:original_object_dict])
if isnothing(constr_name)
constr_name = gensym("constraint")
end
return Symbol(constr_name)
end

The object dictionary is currently stored so that any deletions of Nonlinear constraints do not break the object dictionary:

@expression(m, original_object_dict, object_dictionary(m))

Big-M Tightness

IntervalArithmetic won't necessarily give you the tightest Big-M value for nonlinear GDP.

Improve performance of `distribute_and_over_or!`

Should be done from the bottom up on the expression tree for best performance. However, it is currently done from the top down, which is why we run it in a loop until all clauses are in CNF.

`@disjunction` macro requires a name to be passed to the disjunction

When using a tuple to build a disjunction with @disjunction, a name must be provided or the transformation fails.

julia> fc1=Model()
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: NO_OPTIMIZER      
Solver name: No optimizer attached.       

julia> @variables(fc1,begin
       0  z  6
       0  x  3
       end)
julia> @disjunction(fc1, z==x+3, (z0,x0), reformulation=:big_m, M = 100)

ERROR: UndefVarError: disj_##638 not defined
Stacktrace:
 [1] top-level scope
   @ C:\Users\HD\.julia\packages\DisjunctiveProgramming\fJZjn\src\macros.jl:71      

Look into Alternate CNF

Alternate approaches exist for converting to CNF, which involve preserving clause satisfiability rather than clause equivalence. These approaches prevent exponential size increase in clauses and yield logically consistent results.

Paul Jackson and Daniel Sheridan. Clause form conversions
for boolean circuits. Theory and Applications of Satisfiability
Testing, page 183–198, 2005. doi:10.1007/11527695_15.

infer bigM needs to support `@NLconstraint`

prelim code:

using JuMP

m=Model()
@variable(m,0<=x[i=1:2]<=1)
@variable(m,0<=y<=1)
@NLconstraint(m,e[i=1:2],exp(x[i]) + y >= 0)

e1 = string(e[1])
e1split = split(e1," ")
idx = findfirst(part -> occursin(r"[>=,<=,==]",part), e1split)
e1join = join(e1split[1:idx-1])

vars = all_variables(m)
varnames = [split(string(var),"[")[1] for var in vars]
union!(varnames)

new constraints output for nonlinear models

Since reformulations of nonlinear (or quadratic if using the hull reformulation) constraints requires deleting the original constraint and creating a new constraint, the section in reformulate_disjunction that creates the dictionary with new constraints errors because the disj has been modified.

new_constraints = Dict{Symbol,Any}(
Symbol(bin_var,"[$i]") => disj[i] for i in eachindex(disj)
)

Perspective function

Epsilon should not be a JuMP variable. Make it a scalar and a keyword argument.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.