-
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.
MA experiments, Genetic weights, MomentumTimeline updates (#47)
Added first population weighting to GeneticScheduler, made MA experiments around it (showed its efficiency). Updated MomentumTimeline so now it's results are comparable with JustInTimeTimeline.
- Loading branch information
1 parent
ddf7544
commit afd9b96
Showing
20 changed files
with
479 additions
and
290 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from functools import partial | ||
from random import Random | ||
from typing import IO | ||
|
||
from pathos.multiprocessing import ProcessingPool | ||
|
||
from sampo.generator import SimpleSynthetic | ||
from sampo.scheduler.heft.base import HEFTBetweenScheduler | ||
from sampo.scheduler.heft.base import HEFTScheduler | ||
from sampo.scheduler.multi_agency.block_generator import SyntheticBlockGraphType, generate_block_graph | ||
from sampo.scheduler.multi_agency.multi_agency import Agent, Manager | ||
from sampo.scheduler.topological.base import TopologicalScheduler | ||
|
||
r_seed = Random().randint(0, 100000) | ||
p_rand = SimpleSynthetic(rand=r_seed) | ||
rand = Random(r_seed) | ||
|
||
|
||
def obstruction_getter(i: int): | ||
return None | ||
# return OneInsertObstruction.from_static_graph(0.5, rand, p_rand.work_graph(SyntheticGraphType.SEQUENTIAL, 10)) | ||
|
||
|
||
def log(message: str, logfile: IO): | ||
# print(message) | ||
logfile.write(message + '\n') | ||
|
||
|
||
def run_iteration(args): | ||
iteration = args[0] | ||
schedulers = [HEFTScheduler(), HEFTBetweenScheduler(), TopologicalScheduler()] | ||
|
||
blocks_received = {str(scheduler): 0 for scheduler in schedulers} | ||
for i in range(1, 5): | ||
with open(f'algorithms_efficiency_block_size_{50 * i}_iteration_{iteration}.txt', 'w') as logfile: | ||
logger = partial(log, logfile=logfile) | ||
logger(f'block_size ~ {50 * i}') | ||
|
||
for graph_type in SyntheticBlockGraphType: | ||
contractors = [p_rand.contractor(10) for _ in range(len(schedulers))] | ||
|
||
agents = [Agent(f'Agent {i}', schedulers[i % len(schedulers)], [contractor]) | ||
for i, contractor in enumerate(contractors)] | ||
manager = Manager(agents) | ||
|
||
bg = generate_block_graph(graph_type, 10, [1, 1, 1], lambda x: (None, 50 * i), 0.5, | ||
rand, obstruction_getter, 2, [3, 4], [3, 4], logger=logger) | ||
|
||
scheduled_blocks = manager.manage_blocks(bg, logger=logger) | ||
|
||
# aggregate statistics | ||
for sblock in scheduled_blocks.values(): | ||
blocks_received[str(sblock.agent.scheduler)] += 1 | ||
|
||
# downtimes | ||
logger(' '.join([str(agent.downtime.value) for agent in agents])) | ||
|
||
logger('') | ||
|
||
print('Received blocks statistics:') | ||
for scheduler, blocks in blocks_received.items(): | ||
print(f'{scheduler} {blocks}') | ||
|
||
|
||
if __name__ == '__main__': | ||
pool = ProcessingPool(10) | ||
args = [[i] for i in range(10)] | ||
|
||
pool.map(run_iteration, args) |
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from pathos.multiprocessing import ProcessingPool | ||
|
||
from sampo.generator.base import SimpleSynthetic | ||
from sampo.generator.environment.contractor_by_wg import get_contractor_by_wg | ||
from sampo.scheduler.genetic.base import GeneticScheduler | ||
from sampo.schemas.time import Time | ||
|
||
|
||
def run_test(args) -> list[tuple[Time, Time]]: | ||
graph_size, iterations = args | ||
|
||
result = [] | ||
for i in range(iterations): | ||
ss = SimpleSynthetic() | ||
wg = ss.work_graph(top_border=graph_size) | ||
contractors = [get_contractor_by_wg(wg)] | ||
|
||
baseline_genetic = GeneticScheduler(mutate_order=1.0, | ||
mutate_resources=1.0, | ||
size_selection=200, | ||
size_of_population=200) | ||
|
||
optimized_genetic = GeneticScheduler(mutate_order=1.0, | ||
mutate_resources=1.0, | ||
size_selection=200, | ||
size_of_population=200) | ||
optimized_genetic.set_weights([14, 11, 1, 1, 1, 1, 10]) | ||
|
||
baseline_result = baseline_genetic.schedule(wg, contractors) | ||
my_result = optimized_genetic.schedule(wg, contractors) | ||
|
||
result.append((baseline_result.execution_time, my_result.execution_time)) | ||
|
||
return result | ||
|
||
|
||
if __name__ == '__main__': | ||
num_iterations = 50 | ||
|
||
sizes = [200 * i for i in range(1, num_iterations + 1)] | ||
# iterations = [5 - i for i in range(1, num_iterations + 1)] | ||
iterations = [10 for i in range(1, num_iterations + 1)] | ||
|
||
with ProcessingPool(10) as p: | ||
results_by_size = p.map(run_test, zip(sizes, iterations)) | ||
|
||
print('-------------------------------------------------------------') | ||
print('-------------------------| Results |-------------------------') | ||
print('-------------------------------------------------------------') | ||
with open('genetic_init_res.txt', 'w') as f: | ||
for graph_size, result_list in zip(sizes, results_by_size): | ||
global_ratio = 0 | ||
for baseline_result, my_result in result_list: | ||
ratio = baseline_result / my_result | ||
global_ratio += ratio | ||
global_ratio /= len(result_list) | ||
|
||
res_string = f'Size: {graph_size}, upgrade ratio: {global_ratio}' | ||
print(res_string) | ||
f.write(res_string) | ||
f.write('\n') |
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
Oops, something went wrong.