Minimum Generating Set
MinGenSet
MinGenSet(
numbers: list,
total: int | float,
weight_type: (
int | float
) = float,
max_multiplicity: int = 1,
lowerbound: int = 1,
partition_constraints: list = None,
remove_complement_values: bool = True,
remove_sums_of_two: bool = False,
solver_options: dict = {},
)
This class solves the minimum generating set problem. Given a list of numbers a
and a total value total
,
the goal is to find the smallest list of numbers generating_set
such that:
- the sum of the elements in
generating_set
equalstotal
, and - every element in
a
can be expressed as the sum of some elements ingenerating_set
.
This class solves a more general problem, in which we are also given max_multiplicity
,
the maximum number of times each element in generating_set
can be used to represent elements in a
.
Parameters
-
a
: listA list of numbers.
-
total
: int | floatThe total value that the sum of the elements in the generating set should equal.
-
weight_type
: typeThe type of the numbers in
generating_set
. Default isfloat
. The other option isint
. -
max_multiplicity
: intThe maximum number of times each element in the generating set can be used to represent elements in
a
. Default is 1. -
lowerbound
: intThe minimum number of elements in the generating set. Default is 1.
-
partition_constraints
: listA list of lists, where each inner list is made up of numbers, such that the sum of the numbers in each inner list is equal to
total
. That is, each inner list is a number partition oftotal
. These constraints are imposed as: - each number in an inner list must be obtained by summing up a subset of numbers in the generating set, and - each number in the generating set must be used exactly once to obtain the numbers in the inner list.You cannot set this if
max_multiplicity > 1
. -
remove_complement_values
: boolIf
True
, ifa
contains bothx
andtotal - x
, it keeps only the smallest of them. Default isTrue
. This is always correct to do. If say the generating set is \(g_1, g_2, g_3, g_4\), with \(g_1 + g_2 + g_3 + g_4 = total\). If \(x = g_1 + g_3\), then \(total - x = g_2 + g_4\). So \(total - x\) is expressed as a sum of values in the generating set. -
remove_sums_of_two
: boolIf
True
, it removes elements froma
that are the sum of two other elements ina
. Default isFalse
. This is not always correct to do, as it might lead to a smaller generating set. For example, suppose the generating set is \(g_1, g_2, g_3, g_4\), with \(g_1\) different from \(g_4\) Suppose \(x = g_1 + g_2\), \(y = g_1 + g_3\) and \(x+y \in a\). Then \(x+y\) is expressed as \(2 g_1 + g_2 + g_3\), thus it needs repeating \(g_1\) twice. So \(x+y\) cannot be expressed as a sum of elements in the generating set.You cannot set this to
True
ifmax_multiplicity > 1
.Note
Setting this to
True
always gives a generating set smaller or of the same size (i.e., not larger) as setting it toFalse
. Thus, the size of the former generating set can be used as a lower bound for the size of the latter generating set. -
solver_options : dict
, optionalDictionary with the solver options. Default is
{}
. See solver options documentation.
Source code in flowpaths/mingenset.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
|
get_solution
Returns the solution to the minimum generating set problem, if the model was solved.
Warning
Call the solve
method first.
Source code in flowpaths/mingenset.py
is_solved
Returns True
if the model was solved, False
otherwise.
Source code in flowpaths/mingenset.py
solve
Solves the minimum generating set problem. Returns True
if the model was solved, False
otherwise.