Skip to content

Commit

Permalink
Allow for extendable AND non-extendable blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanLoh committed May 3, 2024
1 parent 9c2a90f commit 6ce31d2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion nenupy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
__copyright__ = "Copyright 2023, nenupy"
__credits__ = ["Alan Loh"]
__license__ = "MIT"
__version__ = "2.7.0"
__version__ = "2.7.1"
__maintainer__ = "Alan Loh"
__email__ = "[email protected]"

Expand Down
5 changes: 3 additions & 2 deletions nenupy/schedule/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,12 +730,13 @@ def __init__(self, lst: Longitude, strict_crossing: bool = True, weight: float =


# --------------------------------------------------------- #
# ------------------------ Methods ------------------------ #
# ------------------------ Methods ------------------b------ #
def get_score(self, indices):
"""
"""
self._is_numpy_instance(indices)
return np.mean(self.score[indices], axis=-1)
# return np.mean(self.score[indices], axis=-1)
return int((self.score[indices]>0.7).any())


# --------------------------------------------------------- #
Expand Down
18 changes: 13 additions & 5 deletions nenupy/schedule/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,9 @@ def book(self, optimize=False, **kwargs):
if kwargs.get('sort_by_difficulty', False):
sort_idx = np.argsort(np.sum(self._cnstScores, axis=1))
block_indices = block_indices[sort_idx]
elif kwargs.get('sort_by_availability', False):
sort_idx = np.argsort(np.sum(self._cnstScores > 0, axis=1))
block_indices = block_indices[sort_idx]

# Block are booked iteratively
# for i, blk in enumerate(self.observation_blocks):
Expand Down Expand Up @@ -1132,17 +1135,22 @@ def extend_scheduled_observations(self, relative_score_threshold: float = 0.8) -

# Prepare the available extensions for each observation block
extend_mask = []
slot_extension = []
# slot_extension = []
slot_extension_indices = []
indices = []
# indices = []
for block in self.observation_blocks:
if not block.isBooked:
continue
extdt = block.max_extended_duration
extend_mask.append(extdt is not None)
n_slots = int(np.ceil(extdt.sec/self.dt.sec))
slot_extension.append(n_slots if extdt is not None else 0)
indices.append(block.blockIdx)
try:
n_slots = int(np.ceil(extdt.sec/self.dt.sec))
except AttributeError: # extdt is None, and doesnt have .sec
slot_extension_indices.append([])
continue

# slot_extension.append(n_slots if extdt is not None else 0)
# indices.append(block.blockIdx)

# Compute the constraint score for each possibility (i.e. from self.nSlots to n_slots)
extended_windows_size = np.arange(block.nSlots + 1, n_slots + 1) + 1 # Add 1 to evaluate the constraints
Expand Down

0 comments on commit 6ce31d2

Please sign in to comment.