-
Notifications
You must be signed in to change notification settings - Fork 0
/
GA_support.py
40 lines (32 loc) · 928 Bytes
/
GA_support.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# !/usr/bin/env python
# --------------------------------------------------------------
# File: GA_support.py
# Project: PyEvoAlg
# Created: Sunday, 8th December 2019 2:13:50 pm
# @Author: Molin Liu, MSc in Data Science
# Contact: [email protected]
# Last Modified: Sunday, 8th December 2019 2:33:14 pm
# Copyright © Rockface 2019 - 2020
# --------------------------------------------------------------
from individual import Individual
import numpy as np
from enum import Enum
class Type(Enum):
MIN = 0
MAX = 1
class GA:
def __init__(self, N, G):
self.N = N
self.G = G
def dominate(x: Individual, y: Individual, type='min'):
'''
Determine if x dominates y.
type = [min, max]
'''
if type == 'min':
result = x.ov[:] <= y.ov[:]
else:
result = x.ov[:] >= y.ov[:]
if False in result:
return False
return True