Skip to content
Snippets Groups Projects
Commit 6e1ce231 authored by Jorrit Schaap's avatar Jorrit Schaap
Browse files

TMSS-1939: logging. loop over evaluate methods. use...

TMSS-1939: logging. loop over evaluate methods. use gridded_weighted_start_time for final score computation
parent 8c3f9941
Branches
Tags
1 merge request!955TMSS-1939
......@@ -190,6 +190,7 @@ def filter_scheduling_units_using_constraints(scheduling_units: [models.Scheduli
assert(scheduling_unit.draft is not None)
assert(scheduling_unit.scheduling_constraints_template is not None)
# TODo: check su within cycle
if can_run_within_station_reservations(scheduling_unit):
if can_run_within_timewindow(scheduling_unit, lower_bound, upper_bound, raise_if_interruped, gridder):
runnable_scheduling_units.append(scheduling_unit)
......@@ -256,19 +257,18 @@ def get_best_scored_scheduling_unit_scored_by_constraints(scheduling_units: [mod
for i, scored_scheduling_unit in enumerate(sorted_scored_scheduling_units_coarse):
logger.debug(" [%03d] %s", i, scored_scheduling_unit)
# Re-evaluate top 5 with fine grid
top5_sorted_scored_scheduling_units_coarse = sorted_scored_scheduling_units_coarse[:5]
top5_scheduling_units = [x.scheduling_unit for x in top5_sorted_scored_scheduling_units_coarse]
top5_sorted_scored_scheduling_units_fine = sort_scheduling_units_scored_by_constraints(top5_scheduling_units, lower_bound_start_time, upper_bound_stop_time, fine_gridder)
# Re-evaluate top 5(or less) with fine grid
top_sorted_scored_scheduling_units_coarse = sorted_scored_scheduling_units_coarse[:5]
top_scheduling_units = [x.scheduling_unit for x in top_sorted_scored_scheduling_units_coarse]
top_sorted_scored_scheduling_units_fine = sort_scheduling_units_scored_by_constraints(top_scheduling_units, lower_bound_start_time, upper_bound_stop_time, fine_gridder)
if top5_sorted_scored_scheduling_units_fine:
if logger.level == logging.DEBUG:
logger.debug("sorted top 5 scored_scheduling_units at fine grid of %s[min]:", fine_gridder.grid_minutes)
for i, scored_scheduling_unit in enumerate(top5_sorted_scored_scheduling_units_fine):
logger.debug(" [%03d] %s", i, scored_scheduling_unit)
if top_sorted_scored_scheduling_units_fine:
logger.info("sorted top %d scored_scheduling_units at fine grid of %s[min]:", len(top_sorted_scored_scheduling_units_fine), fine_gridder.grid_minutes)
for i, scored_scheduling_unit in enumerate(top_sorted_scored_scheduling_units_fine):
logger.info(" [%03d] %s", i, scored_scheduling_unit)
# they are sorted best to worst, so return/use first.
best_scored_scheduling_unit = top5_sorted_scored_scheduling_units_fine[0]
best_scored_scheduling_unit = top_sorted_scored_scheduling_units_fine[0]
return best_scored_scheduling_unit
return None
......@@ -345,6 +345,7 @@ def can_run_at(scheduling_unit: models.SchedulingUnitBlueprint, proposed_start_t
gridder = Gridder()
if not can_run_at_with_time_constraints(scheduling_unit, proposed_start_time):
logger.debug("can_run_at_with_time_constraints: SUB id=%s NO!!", scheduling_unit.id)
return False
if not can_run_at_with_daily_constraints(scheduling_unit, proposed_start_time, gridder=gridder):
......@@ -614,16 +615,12 @@ def can_run_at_with_sky_constraints(scheduling_unit: models.SchedulingUnitBluepr
if "sky" not in constraints:
return True
min_elevation_result = evaluate_sky_min_elevation_constraint(scheduling_unit, proposed_start_time, gridder=gridder)
if not min_elevation_result.is_constraint_met:
return False
transit_result = evaluate_sky_transit_constraint(scheduling_unit, proposed_start_time, gridder=gridder)
if not transit_result.is_constraint_met:
return False
min_distance_result = evaluate_sky_min_distance_constraint(scheduling_unit, proposed_start_time, gridder=gridder)
if not min_distance_result.is_constraint_met:
for evaluate_constraint_method in (evaluate_sky_min_elevation_constraint,
evaluate_sky_transit_constraint,
evaluate_sky_min_distance_constraint):
result = evaluate_constraint_method(scheduling_unit, proposed_start_time, gridder=gridder)
logger.debug("can_run_at_with_sky_constraints: %s", result)
if not result.is_constraint_met:
return False
return True
......@@ -1101,11 +1098,11 @@ def get_earliest_possible_start_time(scheduling_unit: models.SchedulingUnitBluep
earliest_possible_start_time = max(lower_bound, earliest_possible_start_time)
earliest_possible_start_time = round_to_second_precision(earliest_possible_start_time)
logger.info("get_earliest_possible_start_time SUB id=%s lower_bound='%s' earliest_possible_start_time='%s' (took %.1f[s])", scheduling_unit.id, lower_bound, earliest_possible_start_time, _method_elapsed.total_seconds())
logger.debug("get_earliest_possible_start_time SUB id=%s lower_bound='%s' earliest_possible_start_time='%s' (took %.1f[s])", scheduling_unit.id, lower_bound, earliest_possible_start_time, _method_elapsed.total_seconds())
return earliest_possible_start_time
# no constraints yielding a runnable earliest_possible_start_time?
logger.info("get_earliest_possible_start_time SUB id=%s lower_bound='%s' earliest_possible_start_time=None (took %.1f[s])", scheduling_unit.id, lower_bound, _method_elapsed.total_seconds())
logger.debug("get_earliest_possible_start_time SUB id=%s lower_bound='%s' earliest_possible_start_time=None (took %.1f[s])", scheduling_unit.id, lower_bound, _method_elapsed.total_seconds())
return None
......@@ -1134,29 +1131,29 @@ def get_weighted_start_time(scheduling_unit: models.SchedulingUnitBlueprint, low
return at
# with the density_vs_optimal the user can optimize for:
# - a dense schedule where all units are packed near to each other (weight=1)
# - an optimal schedule where all units are positioned at/near the optimal (transit) time (weight=0)
# - a dense schedule where all units are packed near to each other (weight=0)
# - an optimal schedule where all units are positioned at/near the optimal (transit) time (weight=1)
# - or a mix between both (0<weight<1)
density_vs_optimal, created = models.SchedulingConstraintsWeightFactor.objects.get_or_create(
scheduling_constraints_template=scheduling_unit.scheduling_constraints_template,
constraint_name='density_vs_optimal',
defaults={'weight': 1.0})
defaults={'weight': 0.5})
earliest_possible_start_time = get_earliest_possible_start_time(scheduling_unit, lower_bound, gridder=gridder)
if earliest_possible_start_time is not None:
earliest_possible_start_time = max(lower_bound, earliest_possible_start_time)
# ToDo: optimal start time is cached and modified somewhere. get_optimal_start_time does not return the same results for the same arguments. Fix this.
# # ToDo: optimal start time is cached and modified somewhere. get_optimal_start_time does not return the same results for the same arguments. Fix this.
# optimal_start_time = get_optimal_start_time(scheduling_unit, lower_bound, gridder=gridder)
#
# if optimal_start_time is not None:
# optimal_start_time = max(lower_bound, optimal_start_time)
# assert (optimal_start_time-earliest_possible_start_time) < timedelta(hours=24), "SUB id=%s optimal_start_time='%s' should follow earliest_possible_start_time='%s' within 24h" %(scheduling_unit.id, optimal_start_time, earliest_possible_start_time)
# # assert (optimal_start_time-earliest_possible_start_time) < timedelta(hours=24), "SUB id=%s optimal_start_time='%s' should follow earliest_possible_start_time='%s' within 24h" %(scheduling_unit.id, optimal_start_time, earliest_possible_start_time)
#
# weighted_start_time = earliest_possible_start_time + density_vs_optimal.weight * (optimal_start_time-earliest_possible_start_time)
#
# assert can_run_at(scheduling_unit, weighted_start_time, gridder), "SUB id=%s cannot run at weighted_start_time='%s' earliest_possible_start_time='%s' optimal_start_time='%s'" %(scheduling_unit.id, weighted_start_time, earliest_possible_start_time, optimal_start_time)
# # assert can_run_at(scheduling_unit, weighted_start_time, gridder), "SUB id=%s cannot run at weighted_start_time='%s' earliest_possible_start_time='%s' optimal_start_time='%s'" %(scheduling_unit.id, weighted_start_time, earliest_possible_start_time, optimal_start_time)
# return weighted_start_time
# return the first non-None timestamp
......@@ -1202,6 +1199,7 @@ def compute_scheduling_unit_scores(scheduling_unit: models.SchedulingUnitBluepri
scores['project_rank'] = float(models.ProjectRank.LOWEST.value - scheduling_unit.project.rank)/float(models.ProjectRank.LOWEST.value-models.ProjectRank.HIGHEST.value)
weighted_start_time = get_weighted_start_time(scheduling_unit, lower_bound, gridder=gridder)
gridded_weighted_start_time = gridder.grid_time(weighted_start_time)
if 'at' in scheduling_unit.scheduling_constraints_doc.get('time',{}):
at = parser.parse(scheduling_unit.scheduling_constraints_doc['time']['at'], ignoretz=True)
......@@ -1212,20 +1210,19 @@ def compute_scheduling_unit_scores(scheduling_unit: models.SchedulingUnitBluepri
# so, if we start at upper_bound, then density should be 0
scores['density'] = min(1, max(0, (upper_bound-weighted_start_time).total_seconds() / (upper_bound-lower_bound).total_seconds()))
transit_result = evaluate_sky_transit_constraint(scheduling_unit, lower_bound, gridder)
if transit_result.is_constraint_met:
scores[transit_result.constraint_key] = transit_result.score
min_elevation_result = evaluate_sky_min_elevation_constraint(scheduling_unit, lower_bound, gridder)
if min_elevation_result.is_constraint_met:
scores[min_elevation_result.constraint_key] = min_elevation_result.score
min_distance_result = evaluate_sky_min_distance_constraint(scheduling_unit, lower_bound, gridder)
if min_distance_result.is_constraint_met:
scores[min_distance_result.constraint_key] = min_distance_result.score
# compute/get scores per constraint type
for evaluate_method in (evaluate_sky_transit_constraint,
evaluate_sky_min_elevation_constraint,
evaluate_sky_min_distance_constraint,
evaluate_daily_constraints):
# compute the result at the gridded weighted_start_time for cache hits. (margins at bounds are taken into account)
result = evaluate_method(scheduling_unit, gridded_weighted_start_time, gridder)
if result.is_constraint_met:
scores[result.constraint_key] = result.score
return ScoredSchedulingUnit(scheduling_unit=scheduling_unit,
scores=scores,
# return the actual (not the gridded) weighted_start_time
start_time=weighted_start_time)
def get_min_earliest_possible_start_time(scheduling_units: [models.SchedulingUnitBlueprint], lower_bound: datetime, raise_if_interruped: Callable=noop, gridder: Gridder=Gridder()) -> datetime:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment