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.F where N is the problem ID and F is a formulation ID (e.g., p12.a).

Parameters:
pathstr or pathlib.Path

Path to the directory containing this problem. See Problem Directory for the expected directory structure.

Attributes:
pathpathlib.Path

Resolved absolute path to the problem directory.

namestr

Human-readable problem name.

parametersdict[str, Parameter]

Problem data parameters keyed by their names.

descriptionstr

Natural-language description of the problem.

formulationsdict[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 the valid attribute of Formulation to filter.

datadict[str, object] or None

A single concrete instance of problem data.

solutionSolution or None

Optimal solution to the provided instance data, if available.

metadatadict[str, object]

Free-form metadata about the problem. Typically includes a source field with details about the origin of the problem and a notes field with additional commentary.

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