Problem¶
- class formulation_bench.problem.Problem(path)[source]¶
A problem in the FormulationBench dataset.
A problem is an optimization problem (e.g., TSP, CWLP) that admits one or more MILP formulations. Each problem is identified by a unique integer ID. Problems are often referred to by
pN.FwhereNis the problem ID andFis a formulation ID (e.g.,p12.a).- Parameters:
- path
strorpathlib.Path Path to the directory containing this problem. See Problem Directory for the expected directory structure.
- path
- Attributes:
- path
pathlib.Path Resolved absolute path to the problem directory.
- name
str Human-readable problem name.
- parameters
dict[str,Parameter] Problem data parameters keyed by their names.
- description
str Natural-language description of the problem.
- formulations
dict[str,Formulation] MILP formulations associated with this problem, keyed by their formulation ID (e.g.,
"a","b", etc.). This may include formulations that are unfaithful or otherwise invalid; use thevalidattribute ofFormulationto filter.- data
dict[str,object] orNone A single concrete instance of problem data.
- solution
SolutionorNone Optimal solution to the provided instance data, if available.
- metadata
dict[str,object] Free-form metadata about the problem. Typically includes a
sourcefield with details about the origin of the problem and anotesfield with additional commentary.
- path
Examples
Examine problem p12 | Traveling Salesman Problem (TSP):
>>> from formulation_bench import Dataset >>> ds = Dataset("dataset") >>> p12 = ds.problems[12] >>> p12.name 'Traveling Salesman Problem (TSP)' >>> p12.description 'The Traveling Salesman Problem (TSP) aims to find the shortest cycle ...'
Get the list of valid/invalid formulations:
>>> [f_id for f_id, f in p12.formulations.items() if f.valid] ['a', 'b', 'c', 'g', 'h', 'i'] >>> [f_id for f_id, f in p12.formulations.items() if not f.valid] ['d', 'e', 'f']
Access the problem data and solution, if available:
>>> p12.data is not None True >>> p12.solution is not None True >>> p12.data["n"] 16 >>> p12.solution.objective 6859