|
| 1 | +```@meta |
| 2 | +CurrentModule = ModelAnalyzer |
| 3 | +DocTestSetup = quote |
| 4 | + using ModelAnalyzer |
| 5 | +end |
| 6 | +``` |
| 7 | + |
| 8 | +# ModelAnalyzer.jl |
| 9 | + |
| 10 | +This package provides tools for analyzing (and debugging) [JuMP](https://github.com/jump-dev/JuMP.jl) models. |
| 11 | + |
| 12 | +Three main functionalities are provided: |
| 13 | + |
| 14 | +1. **Numerical Analysis**: Check for numerical issues in the model, such as large and small coefficients, |
| 15 | +empty constraints, non-convex quadratic functions. |
| 16 | + |
| 17 | +2. **Feasibility Analysis**: Given an optimized model, or a candidate solution, check if the solutions is |
| 18 | +feasible and optimal (when possible). This includes checking the feasibility of the primal model and |
| 19 | +also the dual model (if available). Complementary slackness conditions are also checked (if applicable). |
| 20 | + |
| 21 | +3. **Infeasibility Analysis**: Given an unsolved of solved model, three steps are made to check for |
| 22 | + infeasibility: |
| 23 | + - Check bounds, integers and binaries consistency is also checked at this point. |
| 24 | + - Propagate bounds in constraints individually, to check if each constraint is infeasible |
| 25 | + given the current variable bounds. This is only done if bounds are ok. |
| 26 | + - Run an IIS (Irreducible Inconsistent Subsystem / irreducible infeasible sets) |
| 27 | + resolver algorithm to find a minimal infeasible subset of constraints. |
| 28 | + This is only done if no issues are found in the previous two steps. |
| 29 | + |
| 30 | +## Installation |
| 31 | + |
| 32 | +You can install the package using the Julia package manager. In the Julia REPL, run: |
| 33 | + |
| 34 | +```julia |
| 35 | +using Pkg |
| 36 | +Pkg.add("https://github.com/jump-dev/ModelAnalyzer.jl") |
| 37 | +``` |
| 38 | + |
| 39 | +## Usage |
| 40 | + |
| 41 | +### Basic usage |
| 42 | + |
| 43 | +Here is a simple example of how to use the package: |
| 44 | + |
| 45 | +```julia |
| 46 | +using JuMP |
| 47 | +using ModelAnalyzer |
| 48 | +using HiGHS # or any other supported solver |
| 49 | +# Create a simple JuMP model |
| 50 | +model = Model(HiGHS.Optimizer) |
| 51 | +@variable(model, x >= 0) |
| 52 | +@variable(model, y >= 0) |
| 53 | +@constraint(model, c1, 2x + 3y == 5) |
| 54 | +@constraint(model, c2, x + 2y <= 3) |
| 55 | +@objective(model, Min, x + y) |
| 56 | +# Optimize the model |
| 57 | +optimize!(model) |
| 58 | + |
| 59 | +# either |
| 60 | + |
| 61 | +# Perform a numerical analysis of the model |
| 62 | +data = ModelAnalyzer.analyze(ModelAnalyzer.Numerical.Analyzer(), model) |
| 63 | +# print report |
| 64 | +ModelAnalyzer.summarize(data) |
| 65 | + |
| 66 | +# or |
| 67 | + |
| 68 | +# Check for solution feasibility and optimality |
| 69 | +data = ModelAnalyzer.analyze(ModelAnalyzer.Feasibility.Analyzer(), model) |
| 70 | +# print report |
| 71 | +ModelAnalyzer.summarize(data) |
| 72 | + |
| 73 | +# or |
| 74 | + |
| 75 | +# Infeasibility analysis (if the model was infeasible) |
| 76 | +data = ModelAnalyzer.analyze( |
| 77 | + ModelAnalyzer.Infeasibility.Analyzer(), |
| 78 | + model, |
| 79 | + optimizer = HiGHS.Optimizer, |
| 80 | +) |
| 81 | +# print report |
| 82 | +ModelAnalyzer.summarize(data) |
| 83 | +``` |
| 84 | + |
| 85 | +The `ModelAnalyzer.analyze(...)` function can always take the keyword arguments: |
| 86 | + * `verbose = false` to condense the print output. |
| 87 | + * `max_issues = n` to limit the maximum number of issues to report for each type. |
| 88 | + |
| 89 | +For certain analysis modes, the `summarize` function can take additional arguments. |
| 90 | + |
| 91 | +### Advanced usage |
| 92 | + |
| 93 | +After any `ModelAnalyzer.analyze(...)` call is performed, the resulting data structure |
| 94 | +can be summarized using `ModelAnalyzer.summarize(data)` as show above, |
| 95 | +or it can be further inspected programmatically. |
| 96 | + |
| 97 | +```julia |
| 98 | +# given a `data` object obtained from `ModelAnalyzer.analyze(...)` |
| 99 | + |
| 100 | +# query the types os issues found in the analysis |
| 101 | +list = ModelAnalyzer.list_of_issue_types(data) |
| 102 | + |
| 103 | +# information about the types of issues found can be printed out |
| 104 | +ModelAnalyzer.summarize(data, list[1]) |
| 105 | + |
| 106 | +# for each issue type, you can get the actual issues found in the analysis |
| 107 | +issues = ModelAnalyzer.list_of_issues(data, list[1]) |
| 108 | + |
| 109 | +# the list of issues of the given type can be summarized with: |
| 110 | +ModelAnalyzer.summarize(data, issues) |
| 111 | + |
| 112 | +# infdividual issues can also be summarized |
| 113 | +ModelAnalyzer.summarize(data, issues[1]) |
| 114 | +``` |
0 commit comments