Skip to content

Commit

Permalink
fix backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Timotshak committed Feb 12, 2024
1 parent 3fe1f51 commit ff72154
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
26 changes: 13 additions & 13 deletions sampo/backend/multiproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from sampo.scheduler.genetic.operators import Individual
from sampo.scheduler.genetic.utils import create_toolbox_using_cached_chromosomes, init_chromosomes_f
from sampo.scheduler.heft import HEFTScheduler, HEFTBetweenScheduler
from sampo.scheduler.heft.prioritization import prioritization
from sampo.scheduler.resource import AverageReqResourceOptimizer
from sampo.scheduler.resources_in_time import AverageBinarySearchResourceOptimizingScheduler
from sampo.scheduler.topological.base import RandomizedTopologicalScheduler
Expand Down Expand Up @@ -42,7 +41,7 @@ def scheduler_info_initializer(wg: WorkGraph,
only_lft_initialization: bool,
is_multiobjective: bool):
global g_wg, g_contractors, g_landscape, g_spec, g_toolbox, g_work_estimator, g_deadline, g_rand, g_weights, \
g_sgs_type, g_only_lft_initialization, g_is_multiobjective
g_sgs_type, g_only_lft_initialization, g_is_multiobjective

g_wg = wg
g_contractors = contractors
Expand Down Expand Up @@ -157,35 +156,36 @@ def generate_first_population(self, size_population: int) -> list[Individual]:
def mapper(key: str):
def randomized_init():
schedule, _, _, order = RandomizedTopologicalScheduler(g_work_estimator, int(g_rand.random() * 1000000)) \
.schedule_with_cache(g_wg, g_contractors, landscape=g_landscape)
.schedule_with_cache(g_wg, g_contractors, landscape=g_landscape)[0]
return schedule, order, g_spec

def init_k_schedule(scheduler_class, k) -> tuple[Schedule | None, list[GraphNode] | None, ScheduleSpec | None]:
try:
return scheduler_class(work_estimator=g_work_estimator,
resource_optimizer=AverageReqResourceOptimizer(k)) \
.schedule(g_wg, g_contractors,
g_spec,
landscape=g_landscape), list(reversed(prioritization(g_wg, g_work_estimator))), g_spec
schedule, _, _, node_order = (scheduler_class(work_estimator=g_work_estimator,
resource_optimizer=AverageReqResourceOptimizer(k))
.schedule_with_cache(g_wg, g_contractors, g_spec,
landscape=g_landscape))[0]
return schedule, node_order[::-1], g_spec
except NoSufficientContractorError:
return None, None, None

if g_deadline is None:
def init_schedule(scheduler_class) -> tuple[Schedule | None, list[GraphNode] | None, ScheduleSpec | None]:
try:
return scheduler_class(work_estimator=g_work_estimator).schedule(g_wg, g_contractors,
landscape=g_landscape), \
list(reversed(prioritization(g_wg, g_work_estimator))), g_spec
schedule, _, _, node_order = (scheduler_class(work_estimator=g_work_estimator)
.schedule_with_cache(g_wg, g_contractors, g_spec,
landscape=g_landscape))[0]
return schedule, node_order[::-1], g_spec
except NoSufficientContractorError:
return None, None, None

else:
def init_schedule(scheduler_class) -> tuple[Schedule | None, list[GraphNode] | None, ScheduleSpec | None]:
try:
(schedule, _, _, _), modified_spec = AverageBinarySearchResourceOptimizingScheduler(
(schedule, _, _, node_order), modified_spec = AverageBinarySearchResourceOptimizingScheduler(
scheduler_class(work_estimator=g_work_estimator)
).schedule_with_cache(g_wg, g_contractors, g_deadline, g_spec, landscape=g_landscape)
return schedule, list(reversed(prioritization(g_wg, g_work_estimator))), modified_spec
return schedule, node_order[::-1], modified_spec
except NoSufficientContractorError:
return None, None, None

Expand Down
4 changes: 1 addition & 3 deletions sampo/scheduler/genetic/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import random
from typing import Optional, Callable
from typing import Optional

from sampo.api.genetic_api import ChromosomeType
from sampo.scheduler.base import Scheduler, SchedulerType
Expand All @@ -8,13 +8,11 @@
from sampo.scheduler.genetic.converter import ScheduleGenerationScheme
from sampo.scheduler.heft.base import HEFTScheduler, HEFTBetweenScheduler
from sampo.scheduler.lft.base import LFTScheduler
from sampo.scheduler.heft.prioritization import prioritization
from sampo.scheduler.resource.average_req import AverageReqResourceOptimizer
from sampo.scheduler.resource.base import ResourceOptimizer
from sampo.scheduler.resource.identity import IdentityResourceOptimizer
from sampo.scheduler.resources_in_time.average_binary_search import AverageBinarySearchResourceOptimizingScheduler
from sampo.scheduler.timeline.base import Timeline
from sampo.scheduler.utils import get_worker_contractor_pool
from sampo.schemas.contractor import Contractor
from sampo.schemas.exceptions import NoSufficientContractorError
from sampo.schemas.graph import WorkGraph, GraphNode
Expand Down
1 change: 0 additions & 1 deletion sampo/scheduler/genetic/operators.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import math
import random
from copy import deepcopy
from functools import partial
from operator import attrgetter
from typing import Callable, Iterable

Expand Down

0 comments on commit ff72154

Please sign in to comment.