def construct_compound_reservation(request_group, semester_start): '''Convert a RequestGroup into a CompoundReservation, translating datetimes to kernel epoch times. The Request windows were already translated into visible windows during the filter_on_visibility step. ''' reservations = [] for index, request in enumerate(request_group.requests): visibility_intervals_for_resources = req_windows_to_kernel_intervals(request.windows.windows_for_resource) kernel_intervals_for_resources = translate_request_windows_to_kernel_windows(visibility_intervals_for_resources, semester_start) # Construct the kernel Reservation res = Reservation(request_group.get_effective_priority(index), request.duration, kernel_intervals_for_resources, previous_solution_reservation=request.scheduled_reservation) # Store the original requests for recovery after scheduling # TODO: Do this with a field provided for this purpose, not this hack res.request_group = request_group res.request = request reservations.append(res) # Combine Reservations into CompoundReservations # Each CompoundReservation represents an actual request to do something compound_res = CompoundReservation(reservations, request_group.operator) return compound_res
def setup(self): s1 = Intervals([{ 'time': 1, 'type': 'start' }, { 'time': 2, 'type': 'end' }]) s2 = Intervals([{ 'time': 2, 'type': 'start' }, { 'time': 4, 'type': 'end' }]) s3 = Intervals([{ 'time': 2, 'type': 'start' }, { 'time': 6, 'type': 'end' }]) self.r1 = Reservation_v3(1, 1, {'foo': s1}) self.r2 = Reservation_v3(1, 2, {'bar': s2}) self.r3 = Reservation_v3(2, 1, {'foo': s3}) self.r4 = Reservation_v3(1, 1, {'foo': s1, 'bar': s2}) self.cr1 = CompoundReservation_v2([self.r1]) self.cr2 = CompoundReservation_v2([self.r1, self.r2], 'and') self.cr3 = CompoundReservation_v2([self.r1, self.r3], 'oneof')
def setup(self): s1 = Intervals([{ 'time': 1, 'type': 'start' }, { 'time': 2, 'type': 'end' }]) # 1-2 s2 = Intervals([{ 'time': 2, 'type': 'start' }, { 'time': 4, 'type': 'end' }]) # --2--4 s3 = copy.copy(s1) s4 = copy.copy(s1) s5 = copy.copy(s2) self.r1 = Reservation_v3(1, 1, {'foo': s1}) self.r2 = Reservation_v3(2, 2, {'bar': s2}) self.r3 = Reservation_v3(1, 1, {'foo': s3}) self.r4 = Reservation_v3(1, 1, {'foo': s4}) self.r5 = Reservation_v3(2, 2, {'bar': s5}) self.cr1 = CompoundReservation_v2([self.r1]) self.cr2 = CompoundReservation_v2([self.r3, self.r2], 'and') self.cr3 = CompoundReservation_v2([self.r4]) self.cr4 = CompoundReservation_v2([self.r5]) self.cr5 = CompoundReservation_v2([self.r4, self.r5], 'oneof') self.gpw = {} self.gpw['foo'] = [{ 'time': 1, 'type': 'start' }, { 'time': 5, 'type': 'end' }] self.gpw2 = {} self.gpw2['foo'] = Intervals([{ 'time': 1, 'type': 'start' }, { 'time': 5, 'type': 'end' }], 'free') self.gpw2['bar'] = Intervals([{ 'time': 1, 'type': 'start' }, { 'time': 5, 'type': 'end' }], 'free') self.sched = Scheduler([self.cr1, self.cr2, self.cr3], self.gpw2, []) self.sched2 = Scheduler([self.cr1, self.cr4], self.gpw2, []) self.sched3 = Scheduler([self.cr5], self.gpw2, [])
def test_build_rr_observation(self): reservation = Reservation(priority=None, duration=10, possible_windows_dict={}) reservation.scheduled_start = 0 reservation.scheduled_resource = '1m0a.doma.bpl' proposal = Proposal({ 'id': 'testPro', 'tag': 'tagPro', 'tac_priority': 39, 'pi': 'me' }) target = ICRSTarget({'name': 'test', 'ra': 23.3, 'dec': 22.2}) request_group = RequestGroup(operator='single', requests=None, proposal=proposal, expires=None, rg_id=333333, is_staff=False, name=None, ipp_value=1.0, observation_type="RAPID_RESPONSE", submitter='') configuration = Mock() configuration.guiding_config = {'mode': 'ON', 'optional': True} configuration.type = 'EXPOSE' configuration.instrument_type = '1M0-FAKE-SCICAM' configuration.constraints = {} configuration.id = 13 configuration.target = target request = Request( configurations=[configuration], windows=None, request_id=22223, ) reservation.request = request reservation.request_group = request_group configdb_interface = Mock() configdb_interface.get_specific_instrument.return_value = 'xx03' configdb_interface.get_autoguider_for_instrument.return_value = 'xx04' received = build_observation(reservation, self.start, configdb_interface) assert_equal(received['request'], 22223) assert_equal(received['site'], 'bpl') assert_equal(received['enclosure'], 'doma') assert_equal(received['telescope'], '1m0a') assert_equal(received['configuration_statuses'][0]['configuration'], 13) assert_equal(received['configuration_statuses'][0]['instrument_name'], 'xx03') assert_equal( received['configuration_statuses'][0]['guide_camera_name'], 'xx04')
def test_schedule_order_dependent_resources(self): s1 = Intervals([{'time': 0, 'type': 'start'}, {'time': 1000, 'type': 'end'}]) s2 = Intervals([{'time': 0, 'type': 'start'}, {'time': 1000, 'type': 'end'}]) r1 = Reservation_v3(1, 30, {'foo': s1, 'goo': s2}) cr = CompoundReservation_v2([r1], 'single') gpw = {} gpw['goo'] = Intervals([{'time': 250, 'type': 'start'}, {'time': 750, 'type': 'end'}]) gpw['foo'] = Intervals([]) # [{'time': 1500, 'type': 'start'}, {'time': 2000, 'type': 'end'}]) fs = FullScheduler_v6([cr], gpw, [], 60) schedule = fs.schedule_all() assert_equal(1, len(schedule['goo'])) s1 = Intervals([{'time': 0, 'type': 'start'}, {'time': 1000, 'type': 'end'}]) s2 = Intervals([{'time': 0, 'type': 'start'}, {'time': 1000, 'type': 'end'}]) r1 = Reservation_v3(1, 30, {'foo': s1, 'goo': s2}) cr = CompoundReservation_v2([r1], 'single') gpw = {} gpw['goo'] = Intervals([{'time': 250, 'type': 'start'}, {'time': 750, 'type': 'end'}]) gpw['foo'] = Intervals([{'time': 1500, 'type': 'start'}, {'time': 2000, 'type': 'end'}]) fs = FullScheduler_v6([cr], gpw, [], 60) schedule = fs.schedule_all() assert_equal(1, len(schedule['goo'])) s1 = Intervals([{'time': 0, 'type': 'start'}, {'time': 1000, 'type': 'end'}]) s2 = Intervals([{'time': 0, 'type': 'start'}, {'time': 1000, 'type': 'end'}]) r1 = Reservation_v3(1, 30, {'foo': s1, 'goo': s2}) cr = CompoundReservation_v2([r1], 'single') gpw = {} gpw['foo'] = Intervals([{'time': 250, 'type': 'start'}, {'time': 750, 'type': 'end'}]) gpw['goo'] = Intervals([{'time': 1500, 'type': 'start'}, {'time': 2000, 'type': 'end'}]) fs = FullScheduler_v6([cr], gpw, [], 60) schedule = fs.schedule_all() assert_equal(1, len(schedule['foo'])) s1 = Intervals([{'time': 0, 'type': 'start'}, {'time': 1000, 'type': 'end'}]) s2 = Intervals([{'time': 0, 'type': 'start'}, {'time': 1000, 'type': 'end'}]) r1 = Reservation_v3(1, 30, {'foo': s1, 'goo': s2}) cr = CompoundReservation_v2([r1], 'single') gpw = {} gpw['foo'] = Intervals([{'time': 250, 'type': 'start'}, {'time': 750, 'type': 'end'}]) gpw['goo'] = Intervals([{'time': 1500, 'type': 'start'}, {'time': 2000, 'type': 'end'}]) fs = FullScheduler_v6([cr], gpw, [], 60) schedule = fs.schedule_all() assert_equal(1, len(schedule['foo']))
def test_schedule_no_available_windows(self): s1 = Intervals([{ 'time': 0, 'type': 'start' }, { 'time': 1000, 'type': 'end' }]) s2 = Intervals([{ 'time': 0, 'type': 'start' }, { 'time': 1000, 'type': 'end' }]) r1 = Reservation_v3(1, 30, {'foo': s1, 'goo': s2}) cr = CompoundReservation_v2([r1], 'single') gpw = {} gpw['goo'] = Intervals([{ 'time': 250, 'type': 'start' }, { 'time': 750, 'type': 'end' }]) fs = FullScheduler_ortoolkit('GUROBI', [cr], gpw, [], 60, 0.01, False) fs.schedule_all()
def construct_many_compound_reservation(request_group, request_index, semester_start): request = request_group.requests[request_index] visibility_intervals_for_resources = req_windows_to_kernel_intervals(request.windows.windows_for_resource) kernel_intervals_for_resources = translate_request_windows_to_kernel_windows(visibility_intervals_for_resources, semester_start) # Construct the kernel Reservation res = Reservation(request_group.get_effective_priority(request_index), request.duration, kernel_intervals_for_resources, previous_solution_reservation=request.scheduled_reservation) # Store the original requests for recovery after scheduling # TODO: Do this with a field provided for this purpose, not this hack res.request_group = request_group res.request = request # Create a CR of type 'single' for kernel scheduling compound_res = CompoundReservation([res], 'single') return compound_res
def test_schedule_5_7_2012(self): s1 = Intervals([{'time': 93710, 'type': 'start'}, {'time': 114484, 'type': 'end'}, {'time': 180058, 'type': 'start'}, {'time': 200648, 'type': 'end'}]) r1 = Reservation_v3(1, 30, {'foo': s1}) s2 = copy.copy(s1) r2 = Reservation_v3(1, 30, {'goo': s2}) cr = CompoundReservation_v2([r1, r2], 'oneof') gpw = {} gpw['foo'] = Intervals([{'time': 90000, 'type': 'start'}, {'time': 201000, 'type': 'end'}]) gpw['goo'] = Intervals([{'time': 90000, 'type': 'start'}, {'time': 201000, 'type': 'end'}]) fs = FullScheduler_v6([cr], gpw, [], 60) fs.schedule_all()
def test_schedule_5_7_2012(self): s1 = Intervals([{ 'time': 93710, 'type': 'start' }, { 'time': 114484, 'type': 'end' }, { 'time': 180058, 'type': 'start' }, { 'time': 200648, 'type': 'end' }]) r1 = Reservation_v3(1, 30, {'foo': s1}) s2 = copy.copy(s1) r2 = Reservation_v3(1, 30, {'goo': s2}) cr = CompoundReservation_v2([r1, r2], 'oneof') gpw = {} gpw['foo'] = Intervals([{ 'time': 90000, 'type': 'start' }, { 'time': 201000, 'type': 'end' }]) gpw['goo'] = Intervals([{ 'time': 90000, 'type': 'start' }, { 'time': 201000, 'type': 'end' }]) slice_size_seconds = 300 fs = FullScheduler_ortoolkit('GUROBI', [cr], gpw, [], slice_size_seconds, 0.01, False) fs.schedule_all()
def setup(self): s1 = Intervals([{ 'time': 1, 'type': 'start' }, { 'time': 2, 'type': 'end' }]) # 1-2 s2 = Intervals([{ 'time': 2, 'type': 'start' }, { 'time': 4, 'type': 'end' }]) # --2--4 s3 = copy.copy(s1) s4 = copy.copy(s1) s5 = copy.copy(s2) s6 = copy.copy(s1) s7 = copy.copy(s1) s8 = copy.copy(s1) s9 = copy.copy(s2) s10 = Intervals([{ 'time': 1, 'type': 'start' }, { 'time': 10, 'type': 'end' }]) s11 = copy.copy(s10) s12 = copy.copy(s10) s13 = copy.copy(s10) self.r1 = Reservation_v3(1, 1, {'foo': s1}) self.r2 = Reservation_v3(2, 2, {'bar': s2}) self.r3 = Reservation_v3(1, 1, {'foo': s3}) self.r4 = Reservation_v3(1, 1, {'foo': s4}) self.r5 = Reservation_v3(2, 2, {'bar': s5}) self.r6 = Reservation_v3(1, 2, {'bar': s5}) self.r7 = Reservation_v3(1, 1, {'bar': s6, 'foo': s5}) self.r8 = Reservation_v3(1, 1, {'foo': s6, 'bar': s7}) self.r9 = Reservation_v3(1, 1, {'foo': s8}) self.r10 = Reservation_v3(2, 2, {'bar': s9}) self.r11 = Reservation_v3(1, 1, {'bar': s10}) self.r12 = Reservation_v3(1, 1, {'bar': s11}) self.r13 = Reservation_v3(1, 1, {'bar': s12}) self.r14 = Reservation_v3(1, 1, {'bar': s13}) self.cr1 = CompoundReservation_v2([self.r1]) self.cr2 = CompoundReservation_v2([self.r3, self.r2], 'and') self.cr3 = CompoundReservation_v2([self.r4]) self.cr4 = CompoundReservation_v2([self.r5]) self.cr5 = CompoundReservation_v2([self.r4, self.r5], 'oneof') self.cr6 = CompoundReservation_v2([self.r3]) self.cr7 = CompoundReservation_v2([self.r2]) self.cr8 = CompoundReservation_v2([self.r4, self.r6], 'oneof') self.cr9 = CompoundReservation_v2([self.r4, self.r1, self.r3], 'oneof') self.cr10 = CompoundReservation_v2([self.r7]) self.cr11 = CompoundReservation_v2([self.r8]) self.cr12 = CompoundReservation_v2([self.r9, self.r10], 'oneof') self.cr13 = CompoundReservation_v2([self.r11]) self.cr14 = CompoundReservation_v2([self.r12]) self.cr15 = CompoundReservation_v2([self.r13]) self.cr16 = CompoundReservation_v2([self.r14]) self.gpw2 = {} self.gpw2['foo'] = Intervals([{ 'time': 1, 'type': 'start' }, { 'time': 10, 'type': 'end' }], 'free') self.gpw2['bar'] = Intervals([{ 'time': 1, 'type': 'start' }, { 'time': 10, 'type': 'end' }], 'free') self.gpw3 = {} self.gpw3['foo'] = Intervals([{ 'time': 5, 'type': 'start' }, { 'time': 10, 'type': 'end' }], 'free') self.gpw3['bar'] = Intervals([{ 'time': 5, 'type': 'start' }, { 'time': 10, 'type': 'end' }], 'free') self.gpw4 = {} self.gpw4['bar'] = Intervals([{ 'time': 1, 'type': 'start' }, { 'time': 10, 'type': 'end' }], 'free') self.fs1 = FullScheduler_v5([self.cr1, self.cr2, self.cr3], self.gpw2, [], 1) self.fs2 = FullScheduler_v5([self.cr1, self.cr4], self.gpw2, [], 1) self.fs3 = FullScheduler_v5([self.cr5], self.gpw2, [], 1) self.fs4 = FullScheduler_v5([self.cr8, self.cr6, self.cr7], self.gpw2, [], 1) self.fs5 = FullScheduler_v5([self.cr10, self.cr2, self.cr3], self.gpw2, [], 1) self.fs6 = FullScheduler_v5([self.cr11, self.cr2, self.cr3], self.gpw2, [], 1) self.fs7 = FullScheduler_v5([self.cr12], self.gpw3, [], 1) self.fs8 = FullScheduler_v5( [self.cr13, self.cr14, self.cr15, self.cr16], self.gpw4, [], 1)
def setup(self, algorithm): s1 = Intervals([{ 'time': 1, 'type': 'start' }, { 'time': 2, 'type': 'end' }]) # 1-2 s2 = Intervals([{ 'time': 2, 'type': 'start' }, { 'time': 4, 'type': 'end' }]) # --2--4 s3 = copy.copy(s1) s4 = copy.copy(s1) s5 = copy.copy(s2) s6 = copy.copy(s1) s7 = copy.copy(s1) s8 = copy.copy(s1) s9 = copy.copy(s2) s10 = Intervals([{ 'time': 1, 'type': 'start' }, { 'time': 10, 'type': 'end' }]) s11 = copy.copy(s10) s12 = copy.copy(s10) s13 = copy.copy(s10) # Priority, Duration, possible_windows_dict self.r1 = Reservation_v3(1, 1, {'foo': s1}) self.r2 = Reservation_v3(2, 2, {'bar': s2}) self.r3 = Reservation_v3(1, 1, {'foo': s3}) self.r4 = Reservation_v3(1, 1, {'foo': s4}) self.r5 = Reservation_v3(2, 2, {'bar': s5}) self.r6 = Reservation_v3(1, 2, {'bar': s5}) self.r7 = Reservation_v3(1, 1, {'bar': s6, 'foo': s5}) self.r8 = Reservation_v3(1, 1, {'foo': s6, 'bar': s7}) self.r9 = Reservation_v3(1, 1, {'foo': s8}) self.r10 = Reservation_v3(2, 2, {'bar': s9}) self.r11 = Reservation_v3(1, 1, {'bar': s10}) self.r12 = Reservation_v3(1, 1, {'bar': s11}) self.r13 = Reservation_v3(1, 1, {'bar': s12}) self.r14 = Reservation_v3(1, 1, {'bar': s13}) self.r15 = Reservation_v3(1, 9, {'bar': s13}) self.r16 = Reservation_v3(1, 9, {'foo': s13}) self.r17 = Reservation_v3(2, 9, {'bar': s13}) self.r18 = Reservation_v3(2, 9, {'foo': s13}) self.r19 = Reservation_v3(1, 1, {'bar': s10}) self.r20 = Reservation_v3(1, 1, {'bar': s10}) self.r21 = Reservation_v3(1, 1, {'bar': s10}) self.cr1 = CompoundReservation_v2([self.r1]) self.cr2 = CompoundReservation_v2([self.r3, self.r2], 'and') self.cr3 = CompoundReservation_v2([self.r4]) self.cr4 = CompoundReservation_v2([self.r5]) self.cr5 = CompoundReservation_v2([self.r4, self.r5], 'oneof') self.cr6 = CompoundReservation_v2([self.r3]) self.cr7 = CompoundReservation_v2([self.r2]) self.cr8 = CompoundReservation_v2([self.r4, self.r6], 'oneof') self.cr9 = CompoundReservation_v2([self.r4, self.r1, self.r3], 'oneof') self.cr10 = CompoundReservation_v2([self.r7]) self.cr11 = CompoundReservation_v2([self.r8]) self.cr12 = CompoundReservation_v2([self.r9, self.r10], 'oneof') self.cr13 = CompoundReservation_v2([self.r11]) self.cr14 = CompoundReservation_v2([self.r12]) self.cr15 = CompoundReservation_v2([self.r13]) self.cr16 = CompoundReservation_v2([self.r14]) self.cr17 = CompoundReservation_v2([self.r15, self.r16], 'and') self.cr18 = CompoundReservation_v2([self.r17]) self.cr19 = CompoundReservation_v2([self.r18]) self.cr20 = CompoundReservation_v2([self.r19]) self.cr21 = CompoundReservation_v2([self.r20]) self.cr22 = CompoundReservation_v2([self.r21]) self.gpw2 = {} self.gpw2['foo'] = Intervals([{ 'time': 1, 'type': 'start' }, { 'time': 10, 'type': 'end' }], 'free') self.gpw2['bar'] = Intervals([{ 'time': 1, 'type': 'start' }, { 'time': 10, 'type': 'end' }], 'free') self.gpw3 = {} self.gpw3['foo'] = Intervals([{ 'time': 5, 'type': 'start' }, { 'time': 10, 'type': 'end' }], 'free') self.gpw3['bar'] = Intervals([{ 'time': 5, 'type': 'start' }, { 'time': 10, 'type': 'end' }], 'free') self.gpw4 = {} self.gpw4['bar'] = Intervals([{ 'time': 1, 'type': 'start' }, { 'time': 10, 'type': 'end' }], 'free') slice_dict = {} slice_dict['foo'] = [0, 1] slice_dict['bar'] = [0, 1] slice_size_seconds = 1 self.fs1 = FullScheduler_ortoolkit(algorithm, [self.cr1, self.cr2, self.cr3], self.gpw2, [], slice_size_seconds, 0.01, False) self.fs2 = FullScheduler_ortoolkit(algorithm, [self.cr1, self.cr4], self.gpw2, [], slice_size_seconds, 0.01, False) self.fs3 = FullScheduler_ortoolkit(algorithm, [self.cr5], self.gpw2, [], slice_size_seconds, 0.01, False) self.fs4 = FullScheduler_ortoolkit(algorithm, [self.cr8, self.cr6, self.cr7], self.gpw2, [], slice_size_seconds, 0.01, False) self.fs5 = FullScheduler_ortoolkit(algorithm, [self.cr10, self.cr2, self.cr3], self.gpw2, [], slice_size_seconds, 0.01, False) self.fs6 = FullScheduler_ortoolkit(algorithm, [self.cr11, self.cr2, self.cr3], self.gpw2, [], slice_size_seconds, 0.01, False) self.fs7 = FullScheduler_ortoolkit(algorithm, [self.cr12], self.gpw3, [], slice_size_seconds, 0.01, False) self.fs8 = FullScheduler_ortoolkit( algorithm, [self.cr13, self.cr14, self.cr15, self.cr16], self.gpw4, [], slice_size_seconds, 0.01, False) self.fs9 = FullScheduler_ortoolkit(algorithm, [self.cr17, self.cr18, self.cr19], self.gpw2, [], slice_size_seconds, 0.01, False) self.fs10 = FullScheduler_ortoolkit(algorithm, [self.cr20, self.cr21, self.cr22], self.gpw2, [], slice_size_seconds, 0.01, False)