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

Is it possible to use this package to optimize the selection of indices for a vector? #115

Closed
Datseris opened this issue Mar 27, 2024 · 2 comments

Comments

@Datseris
Copy link

Hi there,

I just discovered this package and it re-ignited my hopes of solving https://discourse.julialang.org/t/using-a-jump-bin-vector-to-index-an-array-checkbounds-fails-with-type-variableref/102674 via JuMP.

I have the following MWE:

using DisjunctiveProgramming
import HiGHS

# example input to test it with
input = rand(100, 6) .* collect(1:6)'
# objective function
function objective(chosen::AbstractVector{Int})
    # given a vector of integers (columns to select)
    # return a real number. Not possible to write down analytic expression,
    # this is just an example
    sums = [sum(input[:, i]) for i in chosen]
    return mean(sums)
end
# start the model
model = GDPModel(HiGHS.Optimizer)
D = size(input, 2)

# Make as many logical variables as columns
@variable(model, I[1:D], Logical)
# we add a constrain that at most Fmax indicators are true
Fmax = 3
@constraint(model, I in AtMost(Fmax))

# goal: find indices, at most Fmax, where `objective`
# of these indices is maximized
# however, I have the same problem, I don't know how to extract
# an integer from `LogicalVariableRef{Model}` inside the
# `objective` function
@objective(model, Max, objective(I))

# I would hope that this works
optimize!(model, gdp_method = BigM(100, false))
print(model)

my code errors in @objective(model, Max, objective(I)) with

ERROR: MethodError: no method matching objective(::Vector{LogicalVariableRef{Model}})

Which is to be expected. I am facing the same issue as the one I posted in the aforementioned discourse thread.

The question therefore is, is it possible via DisjunctiveProgramming.jl and the usage of some disjunctions, to achieve this: optimize the selection of which columns of a matrix to choose (i.e., a vector of integers), so that when using these specific columns to compute a real number, this real number is maximized?

@hdavid16
Copy link
Owner

Unfortunately no. Your objective function must be an algebraic expression of your decision variables. It has the same limitations as standard mathematical optimization.

@Datseris
Copy link
Author

I suspected so, thank you very much for taking the time to reply!

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