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

Adding variables or objective to overall OptiGraph object #72

Open
avinashresearch1 opened this issue Jan 8, 2023 · 1 comment
Open

Comments

@avinashresearch1
Copy link

avinashresearch1 commented Jan 8, 2023

Hi, Thanks for the exciting toolkit.

I see in the API documentation that the OptiGraph object extends a JuMP.AbstractModel and supports most JuMP.Model functions. My understanding was that one could specify certain OptiNode objects within the OptiGraph, and then one could have a custom overall objective that one would specify in the OptiGraphtaking variables from different OptiNodes.

For example, I would like to only specify feasibility problems in the OptiNodes and then set up an objective for the OptiGraph (instead of using a linear combination as is default).

However, when I try to add a variable or an objective to the Optigraph object, I get a MethodError:

image

  1. I realize that jump_model(node::OptiNode) prints out the respective JuMP model. I was wondering if there is a corresponding function for the OptiGraph
@jalving
Copy link
Member

jalving commented Jan 13, 2023

Hi @avinashresearch1. Thanks for your interest in the package!

An OptiGraph does not support adding variables directly. It requires variables to be defined on OptiNodes (although I have been thinking about adding support for light-weight variable nodes). You can still create your objective function using @objective, you just have to reference variables on the nodes. For example, you should be able to do something like:

graph = OptiGraph()
@optinode(graph, node1)
@optinode(graph, node2)
@variable(node1, x>=0)
@variable(node2, x>=0)
@objective(graph, Min, node1[:x] + node2[:x])

For your second question, the closest thing is aggregate(graph). This copies everything in the optigraph into a new node and returns the node and a dictionary that maps optigraph elements to the new node elements. This would look like:

aggregated_node, ref_dict = aggregate(graph)
aggregated_node_x1 = ref_dict[node1[:x]] 
aggregated_node_x2 = ref_dict[node2[:x]]

The OptiGraph is actually a model object in its own right with a MathOptInterface backend just like a JuMP model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants