Skip to content

Commit e16750a

Browse files
committed
Documenting tupledict.map
1 parent a607d1d commit e16750a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

docs/source/container.md

+11
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,15 @@ subset_values = list(td.select("*", 2, 1))
121121
subset_kv_iterator = td.select(1, "*", "*", with_key=True)
122122
```
123123

124+
## Apply a function to values with `map` method
125+
`tupledict` provides a `map` method to apply a function to each value in the `tupledict`. The following example applies a function to each value in the `tupledict`:
126+
127+
```{code-cell}
128+
td = poi.make_tupledict(range(3), range(2), rule=lambda i, j: i+j)
129+
td_new = td.map(lambda x: x*x)
130+
td, td_new
131+
```
132+
124133
## Building a model with `tupledict`
125134
`tupledict` can be used to store and manipulate multi-dimensional variables, constraints and expressions. Using it correctly will make building model more easily.
126135

@@ -156,6 +165,8 @@ obj = poi.quicksum(x.values(), lambda x: x*x)
156165
model.set_objective(obj, poi.ObjectiveSense.Minimize)
157166
158167
model.optimize()
168+
169+
x_value = x.map(model.get_value)
159170
```
160171

161172
Here we use two utility functions to simplify how we express the sum notation

0 commit comments

Comments
 (0)