Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
iROCKBUNNY committed Oct 11, 2021
1 parent fb51f3a commit 810e9d2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,12 @@ def cx_partialy_matched(ind1, ind2):
cxpoint1, cxpoint2 = sorted(random.sample(range(min(len(ind1), len(ind2))), 2))
part1 = ind2[cxpoint1:cxpoint2+1]
part2 = ind1[cxpoint1:cxpoint2+1]
unipart1 = [gene for gene in part1 if gene not in part2]
unipart2 = [gene for gene in part2 if gene not in part1]
rule1to2 = dict(zip(unipart1, unipart2))
rule2to1 = dict(zip(unipart2, unipart1))
rule1to2 = list(zip(part1, part2))
is_fully_merged = False
while not is_fully_merged:
rule1to2, is_fully_merged = merge_rules(rules=rule1to2)
rule2to1 = {rule[1]: rule[0] for rule in rule1to2}
rule1to2 = dict(rule1to2)
ind1 = [gene if gene not in part2 else rule2to1[gene] for gene in ind1[:cxpoint1]] + part2 + \
[gene if gene not in part2 else rule2to1[gene] for gene in ind1[cxpoint2+1:]]
ind2 = [gene if gene not in part1 else rule1to2[gene] for gene in ind2[:cxpoint1]] + part1 + \
Expand Down Expand Up @@ -782,12 +784,21 @@ run_gavrptw(instance_name, unit_cost, init_cost, wait_cost, delay_cost, ind_size
make_dirs_for_file(path)
```
```python
guess_path_type(path)
```
```python
exist(path, overwrite=False, display_info=True)
```
```python
load_instance(json_file)
```
```python
merge_rules(rules)
```
```python
calculate_distance(customer1, customer2)
```
```python
text2json(customize=False)
```

Expand Down
12 changes: 7 additions & 5 deletions gavrptw/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from csv import DictWriter
from deap import base, creator, tools
from . import BASE_DIR
from .utils import make_dirs_for_file, exist, load_instance
from .utils import make_dirs_for_file, exist, load_instance, merge_rules


def ind2route(individual, instance):
Expand Down Expand Up @@ -112,10 +112,12 @@ def cx_partialy_matched(ind1, ind2):
cxpoint1, cxpoint2 = sorted(random.sample(range(min(len(ind1), len(ind2))), 2))
part1 = ind2[cxpoint1:cxpoint2+1]
part2 = ind1[cxpoint1:cxpoint2+1]
unipart1 = [gene for gene in part1 if gene not in part2]
unipart2 = [gene for gene in part2 if gene not in part1]
rule1to2 = dict(zip(unipart1, unipart2))
rule2to1 = dict(zip(unipart2, unipart1))
rule1to2 = list(zip(part1, part2))
is_fully_merged = False
while not is_fully_merged:
rule1to2, is_fully_merged = merge_rules(rules=rule1to2)
rule2to1 = {rule[1]: rule[0] for rule in rule1to2}
rule1to2 = dict(rule1to2)
ind1 = [gene if gene not in part2 else rule2to1[gene] for gene in ind1[:cxpoint1]] + part2 + \
[gene if gene not in part2 else rule2to1[gene] for gene in ind1[cxpoint2+1:]]
ind2 = [gene if gene not in part1 else rule1to2[gene] for gene in ind2[:cxpoint1]] + part1 + \
Expand Down
17 changes: 17 additions & 0 deletions gavrptw/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,23 @@ def load_instance(json_file):
return None


def merge_rules(rules):
'''gavrptw.uitls.merge_rules(rules)'''
is_fully_merged = True
for round1 in rules:
if round1[0] == round1[1]:
rules.remove(round1)
is_fully_merged = False
else:
for round2 in rules:
if round2[0] == round1[1]:
rules.append((round1[0], round2[1]))
rules.remove(round1)
rules.remove(round2)
is_fully_merged = False
return rules, is_fully_merged


def calculate_distance(customer1, customer2):
'''gavrptw.uitls.calculate_distance(customer1, customer2)'''
return ((customer1['coordinates']['x'] - customer2['coordinates']['x'])**2 + \
Expand Down

0 comments on commit 810e9d2

Please sign in to comment.