Skip to content

Commit

Permalink
Merge pull request #281 from gemini-hlsw/SCHED-408
Browse files Browse the repository at this point in the history
Sched 408: Add Selection to schedule method
  • Loading branch information
stroncod authored Jul 28, 2023
2 parents 72b7503 + 498da78 commit 3a43ab3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions scheduler/core/builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ def build_selector(collector: Collector, num_nights_to_schedule: int):
return Selector(collector=collector, num_nights_to_schedule=num_nights_to_schedule)

@staticmethod
def build_optimizer(selection: Selection, blueprint: OptimizerBlueprint) -> Optimizer:
return Optimizer(selection, algorithm=blueprint.algorithm)
def build_optimizer(blueprint: OptimizerBlueprint) -> Optimizer:
return Optimizer(algorithm=blueprint.algorithm)
18 changes: 10 additions & 8 deletions scheduler/core/components/optimizer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,20 @@ class Optimizer:
All algorithms need to follow the same structure to create a Plan
"""

def __init__(self, selection: Selection, algorithm=None):
self.algorithm = algorithm.setup(selection)
def __init__(self, algorithm=None):
self.algorithm = algorithm
self.selection = None
self.period = None
self.night_events = None

def schedule(self, selection: Selection) -> List[Plans]:
# Create set of plans for the amount of nights
self.selection = selection
self.algorithm.setup(selection)
self.night_events = selection.night_events
# TODO: Assumes that all sites schedule the same amount of nights
# if num_nights_optimize is None:
self.period = len(list(self.night_events.values())[0].time_grid)
self.selection: Selection = selection
# else:
# self.period = num_nights_optimize

def schedule(self) -> List[Plans]:
# Create set of plans for the amount of nights
nights = [Plans(self.night_events, night) for night in range(self.period)]
self.algorithm.schedule(nights)
return nights
Expand Down
12 changes: 6 additions & 6 deletions scheduler/core/service/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def __call__(self):
selection = selector.select(sites=self.sites)

# Execute the Optimizer.
optimizer = self.builder.build_optimizer(selection, Blueprints.optimizer)
plans = optimizer.schedule()
optimizer = self.builder.build_optimizer(Blueprints.optimizer)
plans = optimizer.schedule(selection)

# Calculate plans stats
plan_summary = calculate_plans_stats(plans, collector, selection)
Expand Down Expand Up @@ -134,10 +134,10 @@ def calculate_plans_stats(all_plans: List[Plans],
plan.alt_degs.append(alt_degs)

plan.night_stats = NightStats(f'{plan.time_left()} min',
plan_score,
Conditions.most_restrictive_conditions(plan_conditions),
n_toos,
completion_fraction)
plan_score,
Conditions.most_restrictive_conditions(plan_conditions),
n_toos,
completion_fraction)
n_toos = 0
plan_score = 0
plan_conditions = []
Expand Down
3 changes: 1 addition & 2 deletions scheduler/scripts/run_greedymax.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,14 @@
"GreedyMax"
)
optimizer = SchedulerBuilder.build_optimizer(
selection=selection,
blueprint=optimizer_blueprint
)

# TODO: pass these as parameters
optimizer.period = 1 # number of nights for which to make plans in a single pass
# optimizer_blueprint.algorithm.show_plots = True # show plots

plans = optimizer.schedule()
plans = optimizer.schedule(selection)
print_plans(plans)
print('')

Expand Down
3 changes: 1 addition & 2 deletions scheduler/scripts/run_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,9 @@
"DUMMY"
)
optimizer = SchedulerBuilder.build_optimizer(
selection=selection,
blueprint=optimizer_blueprint
)
plans = optimizer.schedule()
plans = optimizer.schedule(selection)
print_plans(plans)

# Example for Bryan:
Expand Down

0 comments on commit 3a43ab3

Please sign in to comment.