Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect the order of blocks with the same priority in PriorityScheduler #541

Merged
merged 4 commits into from
Jul 27, 2023
Merged
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
4 changes: 2 additions & 2 deletions astroplan/scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ def _make_schedule(self, blocks):
score_array = scorer.create_score_array(time_resolution)

# Sort the list of blocks by priority
sorted_indices = np.argsort(_block_priorities)
sorted_indices = np.argsort(_block_priorities, kind='mergesort')

unscheduled_blocks = []
# Compute the optimal observation time in priority order
Expand Down Expand Up @@ -786,7 +786,7 @@ def _make_schedule(self, blocks):
# does not prevent us from fitting it in.
# loop over valid times and see if it fits
# TODO: speed up by searching multiples of time resolution?
for idx in np.argsort(sum_scores)[::-1]:
for idx in np.argsort(-sum_scores, kind='mergesort'):
if sum_scores[idx] <= 0.0:
# we've run through all optimal blocks
_is_scheduled = False
Expand Down
24 changes: 24 additions & 0 deletions astroplan/tests/test_scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,30 @@ def test_priority_scheduler():
scheduler(blocks, schedule)
scheduler(blocks, schedule)

# Check if the order of equal values is respected:
# 1. For equal priorities in blocks
# 2. For equal scores (boolean_constraint)
constraints = [AirmassConstraint(3, boolean_constraint=True)]
scheduler.constraints = constraints
# Any resolution coarser than this may result in gaps between the blocks
scheduler.time_resolution = 20*u.second
# This only happens with more than 16 items or so
targets_18 = [polaris, polaris, polaris, polaris, polaris, polaris,
polaris, polaris, polaris, polaris, polaris, polaris,
polaris, polaris, polaris, polaris, polaris, polaris]
blocks = [ObservingBlock(t, 4*u.minute, 5, name=i) for i, t in enumerate(targets_18)]

schedule = Schedule(start_time, end_time)
scheduler(blocks, schedule)

for i, t in enumerate(targets_18):
# Order of blocks
block = schedule.observing_blocks[i]
assert block.name == i
if i < len(targets_18) - 1:
# Same score for all timeslots, should be filled from the start without gaps
assert block.end_time.isclose(schedule.observing_blocks[i+1].start_time)


def test_sequential_scheduler():
constraints = [AirmassConstraint(2.5, boolean_constraint=False)]
Expand Down