standard_main

standard_main(input_schema,
              solution_schema,
              solve,
              case_space_table_names=False)

provides standardized command line functionality for a ticdat solve engine

:param input_schema: a TicDatFactory or PanDatFactory defining the input schema

:param solution_schema: a TicDatFactory or PanDatFactory defining the output schema

:param solve: a function that takes a input_schema.TicDat object and returns a solution_schema.TicDat object

:param case_space_table_names - passed through to any TicDatFactory/PanDatFactory write functions that have case_space_table_names as an argument. Will also pass through to case_space_sheet_names for Excel writers. boolean - make best guesses how to add spaces and upper case characters to table names when writing to the file system.

:return: None

Implements a command line signature of

"python engine_file.py --input --output --foresta --errors "

For the input/output command line arguments.

--> endings in ".xls" or ".xlsx" imply reading/writing Excel files

--> endings in ".mdb" or ".accdb" imply reading/writing Access files (TicDatFactory only)

--> ending in ".db" imply reading/writing SQLite database files

--> ending in ".sql" imply reading/writing SQLite text files rendered in schema-less SQL statements (TicDatFactory only)

--> ending in ".json" imply reading/writing .json files

--> otherwise, the assumption is that an input/output directory is being specified, which will be used for reading/writing .csv files. (Recall that .csv format is implemented as one-csv-file-per-table, so an entire model will be stored in a directory containing a series of .csv files)

Defaults are input.xlsx, output.xlsx

The Foresta config file is optional. See ticdat wiki for a description of the Foresta config file.

verify

verify(b, msg)

raise a TicDatError exception if the boolean condition is False

:param b: boolean condition.

:param msg: string argument to the TicDatError construction

:return:

gurobi_env

gurobi_env(*args, **kwargs)

Return an object that can be passed to gurobipy.Model() as the env argument. On an ordinary Python installation, just returns None Useful for Gurobi licensing/DRM issues.

:return: An object that can be passed to gurobipy.Model as the env argument

ampl_format

ampl_format(mod_str, **kwargs)

Return a formatted version of mod_str, using substitutions from kwargs. The substitutions are identified by doubled-braces ('{{' and '}}'). Very similar to str.format, except single braces are left unmolested and double-braces are used to identify substitutions. This allows AMPL mod code to be more readable to AMPL developers.

:param mod_str: the string that has doubled-braced substitutions entries.

:param kwargs: Named arguments map from substitution-entry label to value.

:return: A copy of mod_str with the substitutions performed.

Slicer

Slicer(self, iter_of_iters)

Object to perform multi-index slicing over an index sequence

slice

Slicer.slice(*args)

Perform a multi-index slice. (Not to be confused with the native Python slice) :param args a series of index values or ''. The latter means 'match every value' :return: a list of tuples which match args. :caveat will run faster if gurobipy is available and tuplelist can accommodate the interior iterables

clear

Slicer.clear()

reduce memory overheard by clearing out any archived slicing. this is a no-op if gurobipy is available :return:

Sloc

Sloc(self, s)

A utility class for the slicing on pandas Series. Works just like .loc, except doesn't exception out when encountering an empty slice. All credit for this class goes to the inimitable IL. https://github.com/pydata/pandas/issues/10695

add_sloc

Sloc.add_sloc(s)

adds an .sloc attribute to a the series or to every column of the data frame :param s: either a series or a data frame :return: s if .sloc could be added, None otherwise

LogFile

LogFile(self, path)

Utility class for writing log files. Also enables writing on-the-fly tables into log files.

log_table

LogFile.log_table(table_name,
                  seq,
                  formatter=<function LogFile.<lambda> at 0x132428820>,
                  max_write=10)

Writes a table to the log file. Extremely useful functionality for on the fly errors, warnings and diagnostics. :param log_table : the name to be given to the logged table :param seq: An iterable of iterables. The first iterable lists the field names for the table. The remaining iterables list the column values for each row. The outer iterable is thus of length num_rows + 1, while each of the inner iterables are of length num_cols. :param formatter: a function used to turn column entries into strings :param max_write: the maximum number of table entries to write to the actual log file. :return:

Progress

Progress(self, quiet=False)

Utility class for indicating progress.

numerical_progress

Progress.numerical_progress(theme, progress)

indicate generic progress :param theme: string describing the type of progress being advanced :param progress: numerical indicator to the degree of progress advanced :return: False if GUI indicates solve should gracefully finish, True otherwise

mip_progress

Progress.mip_progress(theme, lower_bound, upper_bound)

indicate progress towards solving a MIP via converging upper and lower bounds :param theme: string describing the type of MIP solve underway :param lower_bound: the best current lower bound to the MIP objective :param upper_bound: the best current upper bound to the MIP objective :return: False if GUI indicates solve should gracefully finish, True otherwise

gurobi_call_back_factory

Progress.gurobi_call_back_factory(theme, model)

Allow a Gurobi model to call mip_progress. Only for minimize :param theme: string describing the type of MIP solve underway :param model: a Gurobi model (or ticdat.Model.core_model) :return: a call_back function that can be passed to Model.optimize

add_cplex_listener

Progress.add_cplex_listener(theme, model)

Allow a CPLEX model to call mip_progress. Only for minimize :param theme: short descriptive string :param model: cplex.Model object (or ticdat.Model.core_model) :return: