Try our new documentation site (beta).
Filter Content By
Version
Text Search
${sidebar_list_label} - Back
Filter by Language
tupledict.sum()
sum ( pattern )
Returns the sum of the values associated with keys that match the
specified pattern. If the values are Gurobi Var
objects, the
result is a LinExpr
. The pattern should provide one value for
each field in the key tuple. A '*'
value indicates that any
value is accepted in that field.
Without arguments, this method returns the sum of all values in the
tupledict
.
Arguments:
pattern: Pattern to match for a key tuple.
Example usage:
x = m.addVars([(1,2), (1,3), (2,3)]) expr = x.sum() # LinExpr: x[1,2] + x[1,3] + x[2,3] expr = x.sum(1, '*') # LinExpr: x[1,2] + x[1,3] expr = x.sum('*', 3) # LinExpr: x[1,3] + x[2,3] expr = x.sum(1, 3) # LinExpr: x[1,3]
![](/wp-content/plugins/hd_documentations/content/images/documentation-ampl-guide.webp?x70725)
![](/wp-content/plugins/hd_documentations/content/images/documentation-cloud.webp?x70725)
![](/wp-content/plugins/hd_documentations/content/images/documentation-example-tour.webp?x70725)
![](/wp-content/plugins/hd_documentations/content/images/documentation-quick-start.webp?x70725)
![](/wp-content/plugins/hd_documentations/content/images/documentation-reference-manuals.webp?x70725)
![](/wp-content/plugins/hd_documentations/content/images/documentation-remote-services.webp?x70725)
![](/wp-content/plugins/hd_documentations/content/images/quickstart-os-linux.webp?x70725)
![](/wp-content/plugins/hd_documentations/content/images/quickstart-os-mac-osx.webp?x70725)
![](/wp-content/plugins/hd_documentations/content/images/quickstart-os-windows.webp?x70725)