sampo.scheduler.genetic.operators#
Overview#
Base class for description of different fitness functions. |
|
Fitness function that relies on finish time. |
|
Fitness function that relies on finish time and the set of resources. |
|
The fitness function is dependent on the set of resources and requires the end time to meet the deadline. |
|
The fitness function is dependent on the cost of resources and requires the end time to meet the deadline. |
|
Class to define a type of individual in genetic algorithm |
|
Object, that include set of functions (tools) for genetic model and other functions related to it. |
|
- |
|
Generates population. |
|
It is necessary to generate valid scheduling, which are satisfied to current dependencies |
|
Selection operator for genetic algorithm. |
|
Check correctness of works order and contractors borders. |
|
Checks that assigned order of works are topologically correct. |
|
Checks that assigned contractors can supply assigned workers. |
|
Get a new part in topologic order for chromosome. |
|
Two-Point crossover for order. |
|
Mutation operator for order. |
|
One-Point crossover for resources. |
|
Mutation function for resources. |
|
Combined crossover function of Two-Point crossover for order and One-Point crossover for resources. |
|
Combined mutation function of mutation for order and mutation for resources. |
|
Mutation for contractors’ resource borders. |
|
Changes numeric values in m x n part of chromosome. |
|
Changes the resource borders to the peak values obtained in the schedule. |
- |
Classes#
- class sampo.scheduler.genetic.operators.FitnessFunction(deadline: sampo.schemas.time.Time | None)#
Bases:
abc.ABCBase class for description of different fitness functions.
- abstract evaluate(schedules: list[sampo.schemas.schedule.Schedule]) list[int]#
Calculate the value of fitness function of the all schedules. It is better when value is less.
- class sampo.scheduler.genetic.operators.TimeFitness(deadline: sampo.schemas.time.Time | None = None)#
Bases:
FitnessFunctionFitness function that relies on finish time.
- evaluate(schedules: list[sampo.schemas.schedule.Schedule]) list[int]#
Calculate the value of fitness function of the all schedules. It is better when value is less.
- class sampo.scheduler.genetic.operators.TimeAndResourcesFitness(deadline: sampo.schemas.time.Time | None = None)#
Bases:
FitnessFunctionFitness function that relies on finish time and the set of resources.
- evaluate(schedules: list[sampo.schemas.schedule.Schedule]) list[int]#
Calculate the value of fitness function of the all schedules. It is better when value is less.
- class sampo.scheduler.genetic.operators.DeadlineResourcesFitness(deadline: sampo.schemas.time.Time)#
Bases:
FitnessFunctionThe fitness function is dependent on the set of resources and requires the end time to meet the deadline.
- evaluate(schedules: list[sampo.schemas.schedule.Schedule]) list[int]#
Calculate the value of fitness function of the all schedules. It is better when value is less.
- class sampo.scheduler.genetic.operators.DeadlineCostFitness(deadline: sampo.schemas.time.Time)#
Bases:
FitnessFunctionThe fitness function is dependent on the cost of resources and requires the end time to meet the deadline.
- evaluate(schedules: list[sampo.schemas.schedule.Schedule]) list[int]#
Calculate the value of fitness function of the all schedules. It is better when value is less.
Functions#
- sampo.scheduler.genetic.operators.init_toolbox(wg: sampo.schemas.graph.WorkGraph, contractors: list[sampo.schemas.contractor.Contractor], worker_pool: sampo.schemas.contractor.WorkerContractorPool, landscape: sampo.schemas.landscape.LandscapeConfiguration, index2node: dict[int, sampo.schemas.graph.GraphNode], work_id2index: dict[str, int], worker_name2index: dict[str, int], index2contractor_obj: dict[int, sampo.schemas.contractor.Contractor], init_chromosomes: dict[str, tuple[sampo.scheduler.genetic.converter.ChromosomeType, float, sampo.schemas.schedule_spec.ScheduleSpec]], mut_order_pb: float, mut_res_pb: float, population_size: int, rand: random.Random, spec: sampo.schemas.schedule_spec.ScheduleSpec, worker_pool_indices: dict[int, dict[int, sampo.schemas.resources.Worker]], contractor2index: dict[str, int], contractor_borders: numpy.ndarray, node_indices: list[int], parents: dict[int, set[int]], resources_border: numpy.ndarray, assigned_parent_time: sampo.schemas.time.Time = Time(0), work_estimator: sampo.schemas.time_estimator.WorkTimeEstimator = DefaultWorkEstimator()) deap.base.Toolbox#
Object, that include set of functions (tools) for genetic model and other functions related to it. list of parameters that received this function is sufficient and complete to manipulate with genetic algorithm
- Returns:
Object, included tools for genetic algorithm
- sampo.scheduler.genetic.operators.copy_chromosome(chromosome: sampo.scheduler.genetic.converter.ChromosomeType) sampo.scheduler.genetic.converter.ChromosomeType#
- sampo.scheduler.genetic.operators.generate_population(n: int, wg: sampo.schemas.graph.WorkGraph, contractors: list[sampo.schemas.contractor.Contractor], spec: sampo.schemas.schedule_spec.ScheduleSpec, work_id2index: dict[str, int], worker_name2index: dict[str, int], contractor2index: dict[str, int], contractor_borders: numpy.ndarray, init_chromosomes: dict[str, tuple[sampo.scheduler.genetic.converter.ChromosomeType, float, sampo.schemas.schedule_spec.ScheduleSpec]], rand: random.Random, work_estimator: sampo.schemas.time_estimator.WorkTimeEstimator = None, landscape: sampo.schemas.landscape.LandscapeConfiguration = LandscapeConfiguration()) list[Individual]#
Generates population. Do not use generate_chromosome function.
- sampo.scheduler.genetic.operators.generate_chromosome(wg: sampo.schemas.graph.WorkGraph, contractors: list[sampo.schemas.contractor.Contractor], work_id2index: dict[str, int], worker_name2index: dict[str, int], contractor2index: dict[str, int], contractor_borders: numpy.ndarray, init_chromosomes: dict[str, tuple[sampo.scheduler.genetic.converter.ChromosomeType, float, sampo.schemas.schedule_spec.ScheduleSpec]], spec: sampo.schemas.schedule_spec.ScheduleSpec, rand: random.Random, work_estimator: sampo.schemas.time_estimator.WorkTimeEstimator = DefaultWorkEstimator(), landscape: sampo.schemas.landscape.LandscapeConfiguration = LandscapeConfiguration()) Individual#
It is necessary to generate valid scheduling, which are satisfied to current dependencies That’s why will be used the approved order of works (HEFT order and Topological sorting) Topological sorts are generating always different HEFT is always the same(now not) HEFT we will choose in 30% of attempts Topological in others
- sampo.scheduler.genetic.operators.select_new_population(population: list[sampo.scheduler.genetic.converter.ChromosomeType], pop_size: int) list[sampo.scheduler.genetic.converter.ChromosomeType]#
Selection operator for genetic algorithm. Select top n individuals in population.
- sampo.scheduler.genetic.operators.is_chromosome_correct(chromosome: sampo.scheduler.genetic.converter.ChromosomeType, node_indices: list[int], parents: dict[int, set[int]], contractor_borders: numpy.ndarray) bool#
Check correctness of works order and contractors borders.
- sampo.scheduler.genetic.operators.is_chromosome_order_correct(chromosome: sampo.scheduler.genetic.converter.ChromosomeType, parents: dict[int, set[int]]) bool#
Checks that assigned order of works are topologically correct.
- sampo.scheduler.genetic.operators.is_chromosome_contractors_correct(chromosome: sampo.scheduler.genetic.converter.ChromosomeType, work_indices: Iterable[int], contractor_borders: numpy.ndarray) bool#
Checks that assigned contractors can supply assigned workers.
- sampo.scheduler.genetic.operators.get_order_part(order: numpy.ndarray, other_order: numpy.ndarray) numpy.ndarray#
Get a new part in topologic order for chromosome. This function is needed to make crossover for order.
- sampo.scheduler.genetic.operators.mate_scheduling_order(ind1: sampo.scheduler.genetic.converter.ChromosomeType, ind2: sampo.scheduler.genetic.converter.ChromosomeType, rand: random.Random, copy: bool = True) tuple[sampo.scheduler.genetic.converter.ChromosomeType, sampo.scheduler.genetic.converter.ChromosomeType]#
Two-Point crossover for order.
- Parameters:
ind1 – first individual
ind2 – second individual
rand – the rand object used for randomized operations
copy – if True individuals will be copied before mating so as not to change them
- Returns:
two mated individuals
- sampo.scheduler.genetic.operators.mutate_scheduling_order(ind: sampo.scheduler.genetic.converter.ChromosomeType, mutpb: float, rand: random.Random, parents: dict[int, set[int]]) sampo.scheduler.genetic.converter.ChromosomeType#
Mutation operator for order. Swap neighbors.
- Parameters:
ind – the individual to be mutated
mutpb – probability of gene mutation
rand – the rand object used for randomized operations
parents – mapping object of works and their parent-works to create valid order
- Returns:
mutated individual
- sampo.scheduler.genetic.operators.mate_resources(ind1: sampo.scheduler.genetic.converter.ChromosomeType, ind2: sampo.scheduler.genetic.converter.ChromosomeType, optimize_resources: bool, rand: random.Random, copy: bool = True) tuple[sampo.scheduler.genetic.converter.ChromosomeType, sampo.scheduler.genetic.converter.ChromosomeType]#
One-Point crossover for resources.
- Parameters:
ind1 – first individual
ind2 – second individual
optimize_resources – if True resource borders should be changed after mating
rand – the rand object used for randomized operations
copy – if True individuals will be copied before mating so as not to change them
- Returns:
two mated individuals
- sampo.scheduler.genetic.operators.mutate_resources(ind: sampo.scheduler.genetic.converter.ChromosomeType, mutpb: float, rand: random.Random, resources_border: numpy.ndarray) sampo.scheduler.genetic.converter.ChromosomeType#
Mutation function for resources. It changes selected numbers of workers in random work in a certain interval for this work.
- Parameters:
ind – the individual to be mutated
resources_border – low and up borders of resources amounts
mutpb – probability of gene mutation
rand – the rand object used for randomized operations
- Returns:
mutated individual
- sampo.scheduler.genetic.operators.mate(ind1: sampo.scheduler.genetic.converter.ChromosomeType, ind2: sampo.scheduler.genetic.converter.ChromosomeType, optimize_resources: bool, rand: random.Random) tuple[sampo.scheduler.genetic.converter.ChromosomeType, sampo.scheduler.genetic.converter.ChromosomeType]#
Combined crossover function of Two-Point crossover for order and One-Point crossover for resources.
- Parameters:
ind1 – first individual
ind2 – second individual
optimize_resources – if True resource borders should be changed after mating
rand – the rand object used for randomized operations
- Returns:
two mated individuals
- sampo.scheduler.genetic.operators.mutate(ind: sampo.scheduler.genetic.converter.ChromosomeType, resources_border: numpy.ndarray, parents: dict[int, set[int]], order_mutpb: float, res_mutpb: float, rand: random.Random) sampo.scheduler.genetic.converter.ChromosomeType#
Combined mutation function of mutation for order and mutation for resources.
- Parameters:
ind – the individual to be mutated
resources_border – low and up borders of resources amounts
parents – mapping object of works and their parent-works to create valid order
order_mutpb – probability of order’s gene mutation
res_mutpb – probability of resources’ gene mutation
rand – the rand object used for randomized operations
- Returns:
mutated individual
- sampo.scheduler.genetic.operators.mutate_resource_borders(ind: sampo.scheduler.genetic.converter.ChromosomeType, mutpb: float, rand: random.Random, contractor_borders: numpy.ndarray) sampo.scheduler.genetic.converter.ChromosomeType#
Mutation for contractors’ resource borders.
- Parameters:
ind – the individual to be mutated
contractor_borders – up borders of contractors capacity
mutpb – probability of gene mutation
rand – the rand object used for randomized operations
- Returns:
mutated individual
- sampo.scheduler.genetic.operators.mutate_values(chromosome_part: numpy.ndarray, row_indexes: numpy.ndarray, col_indexes: numpy.ndarray, low_borders: numpy.ndarray, up_borders: numpy.ndarray, masks: numpy.ndarray, mut_part: int, rand: random.Random) None#
Changes numeric values in m x n part of chromosome. This function is needed to make mutation for resources and resource borders.
- sampo.scheduler.genetic.operators.update_resource_borders_to_peak_values(ind: sampo.scheduler.genetic.converter.ChromosomeType, schedule: sampo.schemas.schedule.Schedule, worker_name2index: dict[str, int], contractor2index: dict[str, int])#
Changes the resource borders to the peak values obtained in the schedule.
- Parameters:
ind – the individual to be updated
schedule – schedule obtained from the individual
worker_name2index – mapping object of resources and their index in chromosome
contractor2index – mapping object of contractors and their index in chromosome
- Returns:
individual with updated resource borders
Attributes#
- sampo.scheduler.genetic.operators.Individual#