-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce LFTScheduler and RandomizedLFTScheduler
with tests
- Loading branch information
Showing
8 changed files
with
80 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,12 @@ | ||
from sampo.scheduler.genetic.base import GeneticScheduler | ||
from sampo.scheduler.topological.base import TopologicalScheduler | ||
from sampo.scheduler.lft.prioritization import lft_prioritization | ||
from sampo.scheduler.heft.base import HEFTScheduler, HEFTBetweenScheduler | ||
from sampo.utilities.validation import validate_schedule | ||
|
||
import pandas as pd | ||
|
||
|
||
def test_multiprocessing(setup_scheduler_parameters): | ||
setup_wg, setup_contractors, setup_landscape = setup_scheduler_parameters | ||
|
||
genetic = GeneticScheduler(number_of_generation=100, | ||
genetic = GeneticScheduler(number_of_generation=10, | ||
mutate_order=0.05, | ||
mutate_resources=0.005, | ||
size_of_population=50) | ||
|
||
genetic.schedule(setup_wg, setup_contractors, landscape=setup_landscape) | ||
|
||
|
||
def test_topological(setup_scheduler_parameters): | ||
setup_wg, setup_contractors, setup_landscape = setup_scheduler_parameters | ||
|
||
topological = TopologicalScheduler() | ||
|
||
schedule = topological.schedule(setup_wg, setup_contractors, landscape=setup_landscape) | ||
|
||
print(schedule.execution_time) | ||
|
||
|
||
def test_lft_scheduling(setup_scheduler_parameters): | ||
setup_wg, setup_contractors, setup_landscape = setup_scheduler_parameters | ||
|
||
scheduler = HEFTScheduler() | ||
schedule = scheduler.schedule(setup_wg, setup_contractors, validate=True, landscape=setup_landscape) | ||
default_time = schedule.execution_time | ||
|
||
scheduler = HEFTScheduler(prioritization_f=lft_prioritization) | ||
schedule = scheduler.schedule(setup_wg, setup_contractors, validate=True, landscape=setup_landscape) | ||
lft_time = schedule.execution_time | ||
|
||
try: | ||
validate_schedule(schedule, setup_wg, setup_contractors) | ||
|
||
except AssertionError as e: | ||
raise AssertionError(f'Scheduler {scheduler} failed validation', e) | ||
|
||
print(default_time, lft_time) | ||
|
||
|
||
def test_lft_scheduling2(setup_scheduler_parameters): | ||
setup_wg, setup_contractors, setup_landscape = setup_scheduler_parameters | ||
|
||
scheduler = HEFTBetweenScheduler() | ||
schedule = scheduler.schedule(setup_wg, setup_contractors, | ||
validate=True, | ||
landscape=setup_landscape) | ||
default_time = schedule.execution_time | ||
|
||
try: | ||
validate_schedule(schedule, setup_wg, setup_contractors) | ||
except AssertionError as e: | ||
raise AssertionError(f'Scheduler {scheduler} failed validation', e) | ||
|
||
print(default_time) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from pytest import fixture | ||
|
||
from sampo.scheduler.lft.base import LFTScheduler, RandomizedLFTScheduler | ||
import random | ||
|
||
|
||
@fixture(params=[LFTScheduler, RandomizedLFTScheduler], | ||
ids=[f'Scheduler: {scheduler}' for scheduler in ['LFTScheduler', 'RandomizedLFTScheduler']]) | ||
def setup_schedulers_and_parameters(request, setup_scheduler_parameters) -> tuple: | ||
scheduler = request.param | ||
if isinstance(scheduler, RandomizedLFTScheduler): | ||
scheduler = scheduler(rand=random.Random(2023)) | ||
else: | ||
scheduler = scheduler() | ||
|
||
setup_wg, setup_contractors, setup_landscape = setup_scheduler_parameters | ||
|
||
return setup_wg, setup_contractors, setup_landscape, scheduler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from sampo.scheduler.lft.prioritization import lft_prioritization | ||
from sampo.schemas.graph import GraphNode | ||
from sampo.schemas.contractor import get_worker_contractor_pool | ||
from tests.scheduler.lft.fixtures import setup_schedulers_and_parameters | ||
|
||
|
||
def test_correct_order(setup_schedulers_and_parameters): | ||
setup_wg, setup_contractors, _, scheduler = setup_schedulers_and_parameters | ||
worker_pool = get_worker_contractor_pool(setup_contractors) | ||
_, node_id2duration = scheduler._contractor_workers_assignment(setup_wg, setup_contractors, worker_pool) | ||
order = lft_prioritization(setup_wg, node_id2duration) | ||
seen: set[GraphNode] = set() | ||
|
||
for node in reversed(order): | ||
if not node.children: | ||
break | ||
assert all([parent in seen for parent in node.parents]) | ||
seen.add(node) | ||
while node.is_inseparable_parent(): | ||
node = node.inseparable_son | ||
seen.add(node) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from sampo.utilities.validation import validate_schedule | ||
from tests.scheduler.lft.fixtures import setup_schedulers_and_parameters | ||
|
||
|
||
def test_lft_scheduling(setup_schedulers_and_parameters): | ||
setup_wg, setup_contractors, setup_landscape, scheduler = setup_schedulers_and_parameters | ||
|
||
schedule = scheduler.schedule(setup_wg, setup_contractors, | ||
validate=True, | ||
landscape=setup_landscape) | ||
lft_time = schedule.execution_time | ||
|
||
assert not lft_time.is_inf() | ||
|
||
try: | ||
validate_schedule(schedule, setup_wg, setup_contractors) | ||
except AssertionError as e: | ||
raise AssertionError(f'Scheduler {scheduler} failed validation', e) |