Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docplex/mp/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ def __init__(self, **kwargs):
self.log_output = False
self.max_threads = get_environment().get_available_core_count()
self.auto_publish = create_default_auto_publish_context()
self.collect_model_statistics = True
self.kpi_reporting = BaseContext()
from docplex.mp.progress import ProgressClock
self.kpi_reporting.filter_level = ProgressClock.Gap
Expand Down Expand Up @@ -322,6 +323,7 @@ class Context(BaseContext):
are saved as a table with KPI name and values. Currently only
csv files are supported. This can be a list of filenames if
multiple KPIs files are to be published.
solver.collect_model_statistics: If ``True``, model statistics are collected before solving.
context.solver.auto_publish.kpis_output_field_name: Name of field for KPI names in KPI output
table. Defaults to 'Name'
context.solver.auto_publish.kpis_output_field_value: Name of field for KPI values for KPI output
Expand Down
49 changes: 26 additions & 23 deletions docplex/mp/solve_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,29 +85,32 @@ def env_kpi_hookfn(kpd):
# It is now modified so that notify start is always performed,
# then we update solve details only if they need to be published
# [[[
self_stats = mdl.statistics
# implementation for https://github.ibm.com/IBMDecisionOptimization/dd-planning/issues/2491
problem_type = mdl._get_cplex_problem_type()
kpis = make_new_kpis_dict(allkpis=mdl._allkpis[:],
sense=mdl._objective_sense.verb,
model_type=problem_type,
int_vars=self_stats.number_of_integer_variables,
continuous_vars=self_stats.number_of_continuous_variables,
semicontinuous_vars = self_stats._number_of_semicontinuous_variables,
semiinteger_vars = self_stats._number_of_semiinteger_variables,
linear_constraints=self_stats.number_of_linear_constraints,
bin_vars=self_stats.number_of_binary_variables,
quadratic_constraints=self_stats.number_of_quadratic_constraints,
total_constraints=self_stats.number_of_constraints,
total_variables=self_stats.number_of_variables)
if the_env.is_wmlworker:
from docplex_wml.worker.worker_utils import make_cplex_new_kpis_dict
new_kpis = make_cplex_new_kpis_dict(mdl)
kpis.update(new_kpis)

the_env.notify_start_solve(kpis)
if auto_publish_details:
the_env.update_solve_details(kpis, transaction=self._transaction)
if context.solver.collect_model_statistics:
self_stats = mdl.statistics
# implementation for https://github.ibm.com/IBMDecisionOptimization/dd-planning/issues/2491
problem_type = mdl._get_cplex_problem_type()
kpis = make_new_kpis_dict(allkpis=mdl._allkpis[:],
sense=mdl._objective_sense.verb,
model_type=problem_type,
int_vars=self_stats.number_of_integer_variables,
continuous_vars=self_stats.number_of_continuous_variables,
semicontinuous_vars = self_stats._number_of_semicontinuous_variables,
semiinteger_vars = self_stats._number_of_semiinteger_variables,
linear_constraints=self_stats.number_of_linear_constraints,
bin_vars=self_stats.number_of_binary_variables,
quadratic_constraints=self_stats.number_of_quadratic_constraints,
total_constraints=self_stats.number_of_constraints,
total_variables=self_stats.number_of_variables)
if the_env.is_wmlworker:
from docplex_wml.worker.worker_utils import make_cplex_new_kpis_dict
new_kpis = make_cplex_new_kpis_dict(mdl)
kpis.update(new_kpis)

the_env.notify_start_solve(kpis)
if auto_publish_details:
the_env.update_solve_details(kpis, transaction=self._transaction)
else:
the_env.notify_start_solve({})

# ---
# parameters override if necessary...
Expand Down