minizinc#


class CostScaler(cost_values: List[float], significant_digits: int)[source]#

Bases: object

Serves to scale floats and converts them into integers (and vice versa) whilst maintaining decimal precision

Parameters:

cost_values: the sequence of cost values whose precision should be maintained in the int realm significant_digits: the number of significant digits that shall at least be maintained

scaled_int(original_value: float) int[source]#

Returns the scaled value as an integer

scaled_float(original_value: float) float[source]#
original_value(scaled_value: float) float[source]#

Returns the original unscaled value from a scaled value

class MiniZincProblem[source]#

Bases: ABC

create_mini_zinc_file(f)[source]#

Writes MiniZinc code

Parameters:

f – an OS-level handle to an open file

abstract get_mini_zinc_code()[source]#
class MiniZincSolver(name='OSICBC', solver_time_seconds=None, fzn_output_path=None)[source]#

Bases: object

Parameters:
  • name – name of solver compatible with miniZinc

  • solver_time_seconds – upper time limit for solver in seconds

  • fzn_output_path – flatZinc output path

log = <Logger sensai.minizinc.MiniZincSolver (WARNING)>#
solve_path(mzn_path: str, log_info=True) str[source]#

Solves the MiniZinc problem stored at the given file path

Parameters:
  • mzn_path – path to file containing MiniZinc problem code

  • log_info – whether to log solver output at INFO level rather than DEBUG level

Returns:

the solver output

solve_problem(problem: MiniZincProblem, keep_temp_file=False, log_info=True) str[source]#

Solves the given MiniZinc problem

Parameters:
  • problem – the problem to solve

  • keep_temp_file – whether to keep the temporary .mzv file

  • log_info – whether to log solver output at INFO level rather than DEBUG level

Returns:

the solver output

get_last_solver_time_secs()[source]#
extract_1d_array_from_output(string_identifier: str, output: str) List[source]#
extract_multi_dim_array_from_output(string_identifier: str, dim: int, output: str, boolean=False) array[source]#
array_to_mini_zinc(a: array, element_cast)[source]#