Movatterモバイル変換


[0]ホーム

URL:


ContentsMenuExpandLight modeDark modeAuto light/dark mode
Gurobi Optimizer Reference Manual
Light LogoDark Logo

Concepts

Features

Reference

Gurobi
Back to top

gurobipy.tuplelist#

classtuplelist#

Gurobi tuple list. This is a sub-class of the Pythonlist class thatis designed to efficiently support a usage pattern that is quite commonwhen building optimization models. In particular, if atuplelist ispopulated with a list of tuples, theselect function on thisclass efficiently selects tuples whose values match specified values inspecified tuple fields. To give an example, the statementl.select(1,'*',5) would select all member tuples whose first fieldis equal to ‘1’ and whose third field is equal to ‘5’. The'*'character is used as a wildcard to indicate that any value is acceptablein that field.

You generally buildtuplelist objects in the same way you wouldbuild standard Python lists. For example, you can use the+=operator to append a new list of items to an existingtuplelist, orthe+ operator to concatenate a pair oftuplelist objects. Youcan also call theappend,extend,insert,pop, andremove functions.

To access the members of atuplelist, you also use standard listfunctions. For example,l[0] returns the first member of atuplelist, whilel[0:10] returns atuplelist containing thefirst ten members. You can also uselen(l) to query the length of alist.

Note thattuplelist objects build and maintain a set of internaldata structures to support efficientselect operations. If you wishto reclaim the storage associated with these data structures, you cancall theclean function.

Atuplelist is designed to store tuples containing scalar values(int,float,string, …). It may produce unpredictableresults with other Python objects, such as tuples of tuples. Thus, youcan store(1,2.0,'abc') in atuplelist, but you shouldn’tstore((1,2.0),'abc').

tuplelist(list)#

tuplelist constructor.

Parameters:

list – Initial list of member tuples.

Returns:

A tuplelist object.

Example:
l=gp.tuplelist([(1,2),(1,3),(2,4)])l=gp.tuplelist([('A','B','C'),('A','C','D')])
select(pattern)#

Returns atuplelist containing all member tuples that match thespecified pattern. The pattern requires one argument for each field inthe member tuple. A scalar argument must match the corresponding fieldexactly. A list argument matches if any list member matches thecorresponding field. A'*' argument matches any value in thecorresponding field.

Parameters:

pattern – Pattern to match for a member tuple.

Example:
l.select(1,3,'*',6)l.select([1,2],3,'*',6)l.select('A','*','C')
clean()#

Discards internal data structure associated with atuplelist object.Note that calling this routine won’t affect the contents of thetuplelist. It only affects the memory used and the performance oflater calls toselect.

Example:
l.clean()
__contains__(val)#

Provides efficient support for the Pythonin operator.

Example:
if(1,2)inl:print("Tuple (1,2) is in tuplelist l")

Help and Feedback

On this page

[8]ページ先頭

©2009-2025 Movatter.jp