How process-intelligence-research/relu_ann_milp works
Main Components
• Library Core (relumip package): This includes the core functionalities to encapsulate the ANN model and generate MIP formulations.
– ann_model.py: Contains abstractions and functions specific to the neural network model formulation.
• Interfaces: A dedicated subpackage (relumip/interfaces) that provides:
– Abstract modeling interface definitions (modeling_interface.py)
– Specific interfaces for Gurobi (gurobi_modeling_interface.py) and Pyomo (pyomo_modeling_interface.py)
– Helper utilities to choose between supported modeling languages (supported_modeling_languages.py and interface_factory.py)
• Utilities (relumip/utils): Contains supporting functionalities like:
– Storage operations (storage.py) for handling data and parameter persistence.
• Documentation & Examples: Provides PDF slides, notebooks, and scripts inside the docs/ and examples/ folder – these show usages and detailed methodology (for instance, “ReLU ANN Slides.pdf” and various Jupyter notebooks).
Out Relationships and Interactions
• Data Flow: Start with the input (pre-trained ReLU ANN models) generated externally (e.g., using TensorFlow). These models are then processed by the core ann_model.
• Interface Utilization: The processed neural network model must be converted into a MIP formulation by calling the corresponding interface:
– Decision Logic that decides which modeling interface (Gurobi or Pyomo) to use as per the user’s environment. This can be mediated via interface_factory.py.
• Output Generation: The formulated MIP model is then passed to the underlying optimization solver (e.g., Gurobi, Pyomo with GLPK, etc.) for the target optimization task.
• Auxiliary Utilities: Secondary modules (in utils) support the operation through storage handling and visualization of results or intermediate states.
Architectural Patterns & Design Principles
• Layered Abstraction: Observe how the project cleanly separates the core MIP formulation (ann_model) from the solver-specific integration (interfaces). This design supports extensibility.
• Factory Pattern: The interface_factory.py suggests a factory method to instantiate the proper modeling interface, which is a standard design pattern that encourages loose coupling.
• Modularity: Different features (model formulation, solver interface, and visualization) are modularized into separate packages/subdirectories, making the system easier to maintain and extend.
a. Components to Include:
– Pre-trained ANN Input: Represent an external component that supplies the neural network model.
– Interface Layer: Represent this as an abstraction connecting the ANN model processor to:
• Gurobi Modeling Interface
• Pyomo Modeling Interface
– Solver/Optimization Engine: Show the MIP solver used (Gurobi or another Pyomo-compatible solver such as GLPK).
– Utility Modules: Optionally add a block for utilities managing storage and visualization, enhancing understanding of results.
– Examples & Documentation: Include a side note that these components are utilized in user examples and for illustrative purposes.
b. Interactions:
– Indicate data flow between the interfaces and the external solvers, emphasizing the conversion from neural network representations to MIP formulations.
Putting It All Together
[Pre-trained ANN Model] → [ANN Model Processing (ann_model)] → [Interface Layer (Gurobi/Pyomo)] → [MIP Solver]
– Emphasize that the separation into these many components is intentional and that each block represents a specific abstraction layer or functionality.