-
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.
fix: lekin examples with forward and backward scheduling
- Loading branch information
1 parent
609deba
commit 0e82863
Showing
18 changed files
with
165 additions
and
33 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 |
---|---|---|
|
@@ -5,4 +5,9 @@ coverage: | |
status: | ||
project: | ||
default: | ||
threshold: 2% | ||
threshold: 3% | ||
|
||
patch: | ||
default: | ||
enabled: false | ||
changes: no |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Examples | ||
|
||
forward scheduling | ||
```shell | ||
|
||
``` | ||
|
||
|
||
backward scheduling | ||
```shell | ||
|
||
``` | ||
|
||
|
||
genetic | ||
```shell | ||
|
||
``` |
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 |
---|---|---|
|
@@ -5,8 +5,6 @@ | |
每个任务有自己的需求日期 | ||
目标为延误日期最少,同时换型最少 | ||
做的事情就是把这个序列的permutation优化一下 | ||
""" | ||
|
||
from typing import Union | ||
|
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
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,11 @@ | ||
class SolverConfig: | ||
def __init__(self, entity_selector=None, move_selector=None, termination=None): | ||
self.entity_selector = entity_selector | ||
self.move_selector = move_selector | ||
self.termination = termination | ||
|
||
|
||
class TerminationConfig: | ||
def __init__(self, seconds_spent_limit=None, max_iterations=None): | ||
self.seconds_spent_limit = seconds_spent_limit | ||
self.max_iterations = max_iterations |
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,65 @@ | ||
import copy | ||
import random | ||
import time | ||
|
||
|
||
def check_constraints(job_assignments): | ||
for i, assignment1 in enumerate(job_assignments): | ||
for j, assignment2 in enumerate(job_assignments): | ||
if i < j: | ||
# Check resource conflict | ||
if assignment1.resource == assignment2.resource: | ||
if not ( | ||
assignment1.timeslot.end_time <= assignment2.timeslot.start_time | ||
or assignment2.timeslot.end_time <= assignment1.timeslot.start_time | ||
): | ||
return False | ||
# Check timeslot conflict | ||
if assignment1.timeslot is None or assignment2.timeslot is None: | ||
return False | ||
return True | ||
|
||
|
||
class LekinSolver(object): | ||
def __init__(self, config): | ||
self.config = config | ||
self.best_solution = None | ||
|
||
def solve(self, schedule): | ||
start_time = time.time() | ||
current_solution = copy.deepcopy(schedule) | ||
self.best_solution = current_solution | ||
tabu_list = [] | ||
iterations = 0 | ||
|
||
while not self._is_termination_reached(start_time, iterations): | ||
neighbors = self.config.move_selector.generate_neighbors(current_solution) | ||
feasible_neighbors = [neighbor for neighbor in neighbors if check_constraints(neighbor.job_assignments)] | ||
|
||
if not feasible_neighbors: | ||
continue | ||
|
||
feasible_neighbors.sort(key=self.config.entity_selector.evaluate) | ||
current_solution = feasible_neighbors[0] | ||
current_cost = self.config.entity_selector.evaluate(current_solution) | ||
best_cost = self.config.entity_selector.evaluate(self.best_solution) | ||
|
||
if current_cost < best_cost: | ||
self.best_solution = current_solution | ||
|
||
tabu_list.append(current_solution) | ||
if len(tabu_list) > self.config.entity_selector.tabu_tenure: | ||
tabu_list.pop(0) | ||
|
||
iterations += 1 | ||
|
||
return self.best_solution | ||
|
||
def _is_termination_reached(self, start_time, iterations): | ||
if self.config.termination.seconds_spent_limit: | ||
if time.time() - start_time > self.config.termination.seconds_spent_limit: | ||
return True | ||
if self.config.termination.max_iterations: | ||
if iterations >= self.config.termination.max_iterations: | ||
return True | ||
return False |
This file was deleted.
Oops, something went wrong.