Problems

class epyglpki.MILProgram

Main problem object

>>> p = MILProgram()
>>> p
<epyglpki.MILProgram object at 0x...>
add_constraint(coeffs={}, lower_bound=False, upper_bound=False, name='')

Add and obtain new constraint object

Parameters:
Returns:

constraint object

Return type:

Constraint

>>> p = MILProgram()
>>> c = p.add_constraint()
>>> c
<epyglpki.Constraint object at 0x...>
add_variable(coeffs={}, lower_bound=False, upper_bound=False, kind='continuous', name='')

Add and obtain new variable object

Parameters:
Returns:

variable object

Return type:

Variable

>>> p = MILProgram()
>>> x = p.add_variable()
>>> x
<epyglpki.Variable object at 0x...>
coeffs(coeffs)

Change or retrieve coefficients (constraint matrix)

Parameters:

coeffs (Mapping of length-2 Sequence, containing one Variable and one Constraint, to Real) – the mapping with coefficients to change ({} to set all coefficients to 0)

Raises:
>>> p = MILProgram()
>>> x = p.add_variable()
>>> y = p.add_variable()
>>> c = p.add_constraint()
>>> d = p.add_constraint()
>>> p.coeffs({(x, c): 3, (d, y): 5.5, (x, d): 0})
>>> x.coeffs()[c] == c.coeffs()[x] == 3
True
>>> y.coeffs()[d] == d.coeffs()[y] == 5.5
True
>>> len(x.coeffs()) == len(d.coeffs()) == 1
True
constraints()

Return a list of the problem’s constraints

Returns:a list of the problem’s constraints
Return type:list of Constraint
>>> p = MILProgram()
>>> c = p.add_constraint()
>>> p.constraints()
[<epyglpki.Constraint object at 0x...>]
>>> d = p.add_constraint()
>>> w = p.constraints()
>>> (c in w) and (d in w)
True
intopt(**controls)

Obtain integer optimization solver object

Parameters:controls – set solver control parameters; see IntOptSolver.controls(), parameter controls
Returns:integer optimization solver object
Return type:IntOptSolver
>>> p = MILProgram()
>>> s = p.intopt()
>>> s
<epyglpki.IntOptSolver object at 0x...>
ipoint(**controls)

Obtain interior point solver object

Parameters:controls – set solver control parameters; see IPointSolver.controls(), parameter controls
Returns:interior point solver object
Return type:IPointSolver
>>> p = MILProgram()
>>> s = p.ipoint()
>>> s
<epyglpki.IPointSolver object at 0x...>
name(name)

Change or retrieve problem name

Parameters:

name (str) – the new problem name (omit for retrieval only)

Returns:

the problem name

Return type:

str

Raises:
>>> p = MILProgram()
>>> p.name()
''
>>> p.name('Programme Linéaire')
'Programme Linéaire'
>>> p.name()
'Programme Linéaire'
>>> p.name('')
''
objective(coeffs={}, constant=0, direction='minimize', name='')

Obtain objective object

Parameters:
Returns:

objective object

Return type:

Objective

>>> p = MILProgram()
>>> o = p.objective()
>>> o
<epyglpki.Objective object at 0x...>
read(type cls, fname, format='GLPK', mpsfmt='free')

Read a problem from a file (class method)

Parameters:
  • fname (str) – the name of the file to read from
  • format (str) – the format of the file read from; either 'GLPK', 'LP', 'MPS', or 'CNFSAT'
  • mpsfmt (str) – MPS-subformat; either 'free' or 'fixed' (ignored when format is not 'MPS')
Raises:
  • ValueError – if format is not 'GLPK', 'LP', 'MPS', or 'CNFSAT'
  • RuntimeError – if an error occurred reading the file

Todo

Add doctest

scaling(*algorithms, factors)

Change, apply and unapply scaling factors

Parameters:
  • algorithms (zero or more str arguments) –

    choose scaling algorithms to apply from among

    • 'auto': choose algorithms automatically (other arguments are ignored)
    • 'skip': skip scaling if the problem is already well-scaled
    • 'geometric': perform geometric mean scaling
    • 'equilibration': perform equilibration scaling
    • 'round': round scaling factors to the nearest power of two
  • factors (Mapping of Variable or Constraint to Real) – the mapping with scaling factors to change ({} to set all factors to 1; omit for retrieval only); values defined here have precedence over the ones generated by algorithms
Returns:

the scaling factor mapping, which only contains non-1 factors

Return type:

dict of Variable or Constraint to float

Raises:
>>> p = MILProgram()
>>> x = p.add_variable()
>>> y = p.add_variable()
>>> c = p.add_constraint()
>>> d = p.add_constraint()
>>> p.coeffs({(x, c): 3e-100, (d, y): 5.5, (x, d): 1.5e200})
>>> p.scaling()
{}
>>> p.scaling('skip', 'geometric', 'equilibration',
...           factors={y: 3}) 
{<epyglpki.Variable object at 0x...>: 3.329...e-67,
 <epyglpki.Variable object at 0x...>: 3.0,
 <epyglpki.Constraint object at 0x...>: 1.001...e+166,
 <epyglpki.Constraint object at 0x...>: 2.002...e-134}
>>> p.scaling(factors={})
{}

Note

If a scaling algorithm is given, all factors are first set to 1:

>>> p.scaling(factors={d: 5.5})
{<epyglpki.Constraint object at 0x...>: 5.5}
>>> p.scaling('round')
{}
simplex(**controls)

Obtain simplex solver object

Parameters:controls – set solver and basis factorization control parameters; see SimplexSolver.controls(), parameter controls
Returns:simplex solver object
Return type:SimplexSolver
>>> p = MILProgram()
>>> s = p.simplex()
>>> s
<epyglpki.SimplexSolver object at 0x...>
variables()

A list of the problem’s variables

Returns:a list of the problem’s variables
Return type:list of Variable
>>> p = MILProgram()
>>> x = p.add_variable()
>>> p.variables()
[<epyglpki.Variable object at 0x...>]
>>> y = p.add_variable()
>>> v = p.variables()
>>> (x in v) and (y in v)
True
write(fname, format='GLPK', mpsfmt='free')

Write the problem to a file

Parameters:
  • fname (str) – the name of the file to write to
  • format (str) – the format of the file written to; either 'GLPK', 'LP', 'MPS', or 'CNFSAT'
  • mpsfmt (str) – MPS-subformat; either 'free' or 'fixed' (ignored when format is not 'MPS')
Raises:
  • ValueError – if format is not 'GLPK', 'LP', 'MPS', or 'CNFSAT'
  • RuntimeError – if an error occurred writing the file

Todo

Add doctest

Previous topic

Welcome to epyglpki’s documentation!

Next topic

Components

This Page