alib.modelcreator¶
-
class
alib.modelcreator.AbstractEmbeddingModelCreator(scenario, gurobi_settings=None, optimization_callback=<function gurobi_callback>, lp_output_file=None, potential_iis_filename=None, logger=None)¶ Abstract model creator designed specifically to tackle the Virtual Network Embedding Problem. Subclass this for more specific LPs dealing with VNEP. In particular, this class extends the AbstractModelCreator by instantiating some (generally needed) variables and generating appropriate constraints. Furthermore, it adds support for different objectives.
-
create_constraints()¶
-
create_constraints_bound_node_and_edge_load_by_capacities()¶
-
create_constraints_other_than_bounding_loads_by_capacities()¶
-
create_objective()¶
-
create_variables()¶
-
create_variables_embedding_decision()¶
-
create_variables_other_than_embedding_decision_and_request_load()¶
-
create_variables_request_load()¶
-
plugin_constraint_embed_all_requests()¶
-
plugin_objective_maximize_profit()¶
-
plugin_objective_minimize_cost()¶
-
preprocess_input()¶
-
-
class
alib.modelcreator.AbstractModelCreator(gurobi_settings=None, optimization_callback=<function gurobi_callback>, lp_output_file=None, potential_iis_filename=None, logger=None)¶ Abstract basis for classes creating Mixed-Integer or Linear Programming models. Subclass this for creating Gurobi models.
Provides essential functionality as well as a structured way to create the model and measure the time needed to create, execute and post-process the model.
-
apply_gurobi_settings(gurobiSettings)¶ Apply gurobi settings.
Parameters: gurobiSettings – Returns:
-
compute_fractional_solution()¶ - Assuming that the original model was a Mixed-Integer Program, this function relaxes the integrality conditions
- on variables and solves the corresponding LP using Gurobi.
Returns: GurobiStatus together with a class corresponding to the solution computed in the LP
-
compute_integral_solution()¶ Abstract function computing an integral solution to the model (generated before).
Returns: Result of the optimization consisting of an instance of the GurobiStatus together with a result detailing the solution computed by Gurobi.
-
create_constraints()¶
-
create_objective()¶
-
create_variables()¶
-
getParam(param)¶
-
init_model_creator()¶ - Initializes the modelcreator by generating the model. Afterwards, model.compute() can be called to let
- Gurobi solve the model.
Returns:
-
post_process_fractional_computation()¶
-
post_process_integral_computation()¶
-
preprocess_input()¶
-
recover_fractional_solution_from_variables()¶
-
recover_integral_solution_from_variables()¶
-
relax_model()¶
-
reset_all_parameters_to_default()¶
-
reset_gurobi_parameter(param)¶
-
set_gurobi_parameter(param, value)¶
-
-
class
alib.modelcreator.AlgorithmResult¶ Abstract Algorithm result only specifying specific functions and no data storage capabilities.
-
cleanup_references(original_scenario)¶
-
get_solution()¶ Returns: the solution (as a namedtuple) stored in this class; abstract function
-
-
class
alib.modelcreator.GurobiSettings(mipGap=None, iterationlimit=None, nodeLimit=None, heuristics=None, threads=None, timelimit=None, MIPFocus=None, rootCutPasses=None, cuts=None, BarConvTol=None, OptimalityTol=None, Presolve=None, nodefilestart=None, method=None, nodemethod=None, numericfocus=None, crossover=None, logtoconsole=0)¶ Represents parameter settings for gurobi.
-
setTimeLimit(newTimeLimit)¶
-
-
class
alib.modelcreator.GurobiStatus(status=1, solCount=0, objValue=1e+100, objBound=1e+100, objGap=1e+100, integralSolution=True)¶ Represents the status information of Gurobi after its execution.
In particular, this class stores Gurobi’s status code, the solution count, the objective value, the objective bound, the objective gap and whether an integral solution was computed.
-
CUTOFF= 6¶
-
INFEASIBLE= 3¶
-
INF_OR_UNBD= 4¶
-
INTERRUPTED= 11¶
-
IN_PROGRESS= 14¶
-
ITERATION_LIMIT= 7¶
-
LOADED= 1¶
-
NODE_LIMIT= 8¶
-
NUMERIC= 12¶
-
OPTIMAL= 2¶
-
SOLUTION_LIMIT= 10¶
-
SUBOPTIMAL= 13¶
-
TIME_LIMIT= 9¶
-
UNBOUNDED= 5¶
-
getMIPGap()¶
-
getObjectiveBound()¶
-
getObjectiveValue()¶
-
hasFeasibleStatus()¶
-
isFeasible()¶
-
isIntegralSolution()¶
-
isOptimal()¶
-
-
class
alib.modelcreator.LPData(iteration_count, objective_bound)¶ -
iteration_count¶ Alias for field number 0
-
objective_bound¶ Alias for field number 1
-
-
class
alib.modelcreator.LogEntry(globaltime, time_within_gurobi, data)¶ -
data¶ Alias for field number 2
-
globaltime¶ Alias for field number 0
-
time_within_gurobi¶ Alias for field number 1
-
-
class
alib.modelcreator.MIPData(node_count, objective_value, objective_bound, solution_count, callback_code)¶ -
callback_code¶ Alias for field number 4
-
node_count¶ Alias for field number 0
-
objective_bound¶ Alias for field number 2
-
objective_value¶ Alias for field number 1
-
solution_count¶ Alias for field number 3
-
-
exception
alib.modelcreator.ModelcreatorError¶
-
exception
alib.modelcreator.SolutionError¶
-
class
alib.modelcreator.TemporalLog(log_interval_in_seconds=30.0)¶ Class detailing the solution process of Gurobi during its execution.
Data is (should) be added to this class during the gurobi callback.
-
add_log_data(data, time_within_gurobi, force_new_entry=False)¶
-
set_global_start_time(t)¶
-
set_root_relaxation_entry(data, time_within_gurobi)¶
-
-
exception
alib.modelcreator.TemporalLogError¶
-
class
alib.modelcreator.TemporalLog_Disabled¶ -
add_log_data(data, time_within_gurobi, force_new_entry=False)¶
-
set_global_start_time(t)¶
-
set_root_relaxation_entry(data, time_within_gurobi)¶
-
-
alib.modelcreator.build_construct_name(spec)¶ Build a construct_name function.
This is used e.g. to construct the LP variable names.
The
specparameter defines a list of argument names of the resulting name constructor.The resulting name constructor is a function with one positional argument (
name) and keyword arguments defined inspec. The constructed name starts with thenamearguments and then contains the given keyword arguments in the order ofspec.Keyword arguments are formatted as
"_prefix[value]"where the prefix is the argument key if the prefix itself is unset orNone. If the argument has a custom formatter, it is called on the value.Example 1:
>>> construct_name = build_construct_name([ ... ("req_name", "req"), ... "vnode", ... "snode", ... "vedge", ... "sedge", ... ]) ... >>> construct_name( ... "node_mapping", ... req_name="req1", ... vnode="i", ... snode="u", ... ) ... "node_mapping_req[req1]_vnode[i]_snode[u]"
Example 2:
>>> construct_name = build_construct_name([ ... ("bag", None, lambda v: "_".join(sorted(v))), ... ]) ... >>> construct_name( ... "name", ... bag={"i", "j", "k"} ... ) ... "name_bag[i_j_k]"
Parameters: spec – list of argument names or tuples of (argument name, prefix, formatter), where trailingNonevalues can be left outReturns: construct_name function
-
alib.modelcreator.construct_name(name, **kwargs)¶
-
alib.modelcreator.gurobi_callback(model, where)¶ A guronbi callback used to log the temporal progress during the exection process of gurobi.
Parameters: - model – the gurobi model from which the callback is executed
- where – code referencing for what reason (where in the execution) the callback is executed.
Returns:
-
alib.modelcreator.isFeasibleStatus(status)¶