def test_improvement_with_ls(self): job_a = Job(0, [1, 5]) job_b = Job(1, [5, 1]) flow_shop_2 = Flowshop(2, 2, [job_a, job_b]) swap_neighbors = create_swap_neighbors(flow_shop_2) insert_neighbors = create_insert_neighbors(flow_shop_2) scheduling = Ordonnancement(job_a.nb_op) scheduling.ordonnancer_liste_job([job_b, job_a]) new_scheduling_swap = local_search_swap(scheduling, 1, max_neighbors_nb=50, neighbors=swap_neighbors) new_scheduling_insert = local_search_insert(scheduling, 1, max_neighbors_nb=50, neighbors=insert_neighbors) self.assertTrue(scheduling.duree() == 11) self.assertTrue(new_scheduling_swap.duree() < scheduling.duree()) self.assertTrue(new_scheduling_insert.duree() < scheduling.duree()) self.assertTrue(new_scheduling_swap.duree() == 7) self.assertTrue(new_scheduling_insert.duree() == 7) self.assertEqual(len(new_scheduling_swap.sequence()), 2) self.assertEqual(len(new_scheduling_insert.sequence()), 2) for job in [job_a, job_b]: self.assertIn(job, new_scheduling_swap.sequence()) self.assertIn(job, new_scheduling_insert.sequence())
def add_job(context, request): job = Job() job._id = ''.join(random.choice(string.ascii_lowercase) for i in range(24)) job.description = "Fake job" _JOBS.append(job) response = Response("OK", 200) return response
def start(): global job if not client.is_connected(): client.connect(local_path / "data", "test-model", None) job_spec = request.json options = job_spec["options"] job = Job(options, client, logger) header = job.init_data_file() socketio.emit('job header', header) logger.log("Job started, connected to inputs {} and outputs {}".format( client.get_input_ids(), client.get_output_ids())) message = "\nOptimization started: {} designs / {} generations".format( job.num_designs, job.max_gen) socketio.emit('server message', {"message": message}) if client.get_ss_connection() is not None: ss_path = client.get_dir(["jobs", job.get_id(), "images"]) os.makedirs(ss_path, exist_ok=True) if client.get_connection(): do_next() else: run_local() return jsonify({"status": "success", "job_id": str(job.get_path())})
def __init__(self, infos: List[str]): self.name = infos.pop(0) self.komplete_info = infos.pop(0) jobs_and_machines = infos.pop(0).split(" ") self.job_count = int(jobs_and_machines[1]) self.machine_count = int(jobs_and_machines[2]) self.jobs = list() for job_id, job_info in enumerate(infos): self.jobs.append(Job(job_info, job_id + 1))
def test_vasp_001_shell_job(self): """ Extracts a job from a vasp calculation and asserts the results. """ config = Job("External Job", os.path.join(FIXTURES_DIR, "vasp/test-001")).to_json() self._clean_job_config(config) self.assertDeepAlmostEqual( config, read_json(os.path.join(FIXTURES_DIR, "vasp", "shell-job.json")))
def test_sift_up(create_scheduler_with_jobs): scheduler = create_scheduler_with_jobs def job_f(): return None job_f_time = datetime.datetime.now() + datetime.timedelta(minutes=2) job_f_hours, job_f_minutes = job_f_time.hour, job_f_time.minute job = Job(job_f, str(job_f_hours) + ":" + str(job_f_minutes)) job.next_run = job_f_time scheduler.jobs.append(job) scheduler.sift_up(scheduler.jobs, len(scheduler.jobs) - 1) assert scheduler.jobs[0].name == "job_f"
# Make sure the game is properly defined validate(src.utils.game_module) # For debugging with heapy. if args.debug: src.debug.init_debug(comm.Get_rank()) send = src.debug.debug_send(comm.send) recv = src.debug.debug_recv(comm.recv) abort = src.debug.debug_abort(comm.Abort) initial_position = src.utils.game_module.initial_position() process = Process(comm.Get_rank(), comm.Get_size(), comm, send, recv, abort, stats_dir=args.statsdir) if process.rank == process.root: initial_gamestate = GameState(GameState.INITIAL_POS) initial_job = Job(Job.LOOK_UP, initial_gamestate, process.rank, Job.INITIAL_JOB_ID) process.add_job(initial_job) process.run() comm.Barrier()
import unittest from src.job import Job job_1 = Job(1, [1, 1, 1, 1, 10]) job_2 = Job(2, [1, 1, 1, 4, 8]) job_3 = Job(3, [1, 1, 1, 4, 8]) job_2b = Job(2, [1, 1, 1, 4, 8]) class TestJobClassMethods(unittest.TestCase): def test_eq(self): self.assertNotEqual(job_1, job_2) self.assertNotEqual(job_2, job_3) self.assertEqual(job_2, job_2b) if __name__ == '__main__': unittest.main()
import unittest from src import initial_population as ip from src.job import Job from src.flowshop import Flowshop from src.ordonnancement import Ordonnancement MAXINT = 10000 job_1 = Job(1, [3, 2, 1, 2, 10]) job_2 = Job(2, [8, 4, 0, 2, 8]) job_3 = Job(3, [12, 1, 7, 5, 2]) job_4 = Job(4, [2, 5, 9, 3, 3]) job_5 = Job(5, [1, 3, 1, 1, 1]) l_job = [job_1, job_2, job_3, job_4, job_5] flowshop_1 = Flowshop(5, 5, l_job) flowshop_2 = Flowshop() flowshop_2.definir_par("data\\dataset3\\jeu2.txt") seq_1 = [job_3, job_1, job_5, job_2, job_4] seq_2 = [job_1, job_2, job_4, job_3, job_5] seq_3 = [job_1, job_4, job_3, job_2, job_5] class MyTestCase(unittest.TestCase): def test_initial_population_warnings(self): size = 100 with self.assertWarns(Warning): # Deterministic prop too high ip.initial_pop(flowshop_1, 0.5, 0.5, False, size) size = 150 with self.assertWarns(Warning): # Size too high ip.initial_pop(flowshop_1, 1.0, 0.0, False, size)
import unittest from src.ordonnancement import Ordonnancement from src.job import Job job_1 = Job(1, [1, 1, 1, 1, 10]) job_2 = Job(2, [1, 1, 1, 4, 8]) job_3 = Job(3, [2, 1, 3, 5, 1]) job_4 = Job(4, [2, 5, 5, 3, 3]) job_5 = Job(5, [1, 1, 3, 7, 1]) ord_1 = Ordonnancement(job_1.nb_op) ord_2 = Ordonnancement(job_1.nb_op) ord_3 = Ordonnancement(job_1.nb_op) ord_1.ordonnancer_liste_job([job_2, job_3, job_4, job_5, job_1]) ord_2.ordonnancer_liste_job([job_1, job_4, job_5, job_2, job_3]) ord_3.ordonnancer_liste_job([job_2, job_3, job_4, job_5, job_1]) class TestOrdonnancementClassMethods(unittest.TestCase): def test_eq(self): self.assertEqual(ord_1, ord_3) self.assertNotEqual(ord_1, ord_2) if __name__ == '__main__': unittest.main()
:param ordonnancement: an Ordonnancement object where the scheduling of all jobs is done (in other words which represents a solution to an instance of the flow-shop permutation problem) :param file_path: path where the html file corresponding to the representation of the solution is stored (it needs to have the character "/" at the end or be the empty string) :param file_name: name of the html file corresponding to the representation of the solution :param show_durations: boolean which indicates if the duration of the tasks have to be represented (True by default) """ figure, figure_name = create_solution_figure(ordonnancement, show_durations) if not file_name == "": figure_name = file_name figure.write_html(file_path + figure_name + '.html') return None # "main" to give an example of how to use the "visualisation.py" methods if __name__ == "__main__": a = Job(1, [1, 1, 1, 1, 10]) b = Job(2, [1, 1, 1, 4, 8]) c = Job(3, [2, 1, 3, 5, 1]) d = Job(4, [2, 5, 5, 3, 3]) e = Job(5, [1, 1, 3, 7, 1]) scheduling = Ordonnancement(5) scheduling.ordonnancer_job(a) scheduling.ordonnancer_job(b) scheduling.ordonnancer_job(c) scheduling.ordonnancer_job(d) scheduling.ordonnancer_job(e) # show_solution_figure(scheduling) save_solution_as_html(scheduling)