| 443 | cpdef int number_of_variables(self): |
| 444 | r""" |
| 445 | Returns the number of variables used so far. Note that this is |
| 446 | backend-dependent, i.e. we count solver's variables rather than |
| 447 | user's variables. An example of the latter can be seen below: |
| 448 | Gurobi converts double inequalities, i.e. inequalities like |
| 449 | `m <= c^T x <= M`, with `m<M`, into equations, by adding extra |
| 450 | variables: `c^T x + y = M`, `0 <= y <= M-m`. |
| 451 | |
| 452 | EXAMPLE:: |
| 453 | sage: p = MixedIntegerLinearProgram() |
| 454 | sage: p.add_constraint(p[0] - p[2], max = 4) |
| 455 | sage: p.number_of_variables() |
| 456 | 2 |
| 457 | sage: p.add_constraint(p[0] - 2*p[1], min = 1) |
| 458 | sage: p.number_of_variables() |
| 459 | 3 |
| 460 | sage: p = MixedIntegerLinearProgram(solver="glpk") |
| 461 | sage: p.add_constraint(p[0] - p[2], min = 1, max = 4) |
| 462 | sage: p.number_of_variables() |
| 463 | 2 |
| 464 | sage: p = MixedIntegerLinearProgram(solver="gurobi") # optional - Gurobi |
| 465 | sage: p.add_constraint(p[0] - p[2], min = 1, max = 4) # optional - Gurobi |
| 466 | sage: p.number_of_variables() # optional - Gurobi |
| 467 | 3 |
| 468 | """ |
| 469 | return self._backend.ncols() |
| 470 | |