Skip to content

Commit

Permalink
Crossover is done.
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-axcient committed May 12, 2018
1 parent 09f9821 commit d110857
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 47 deletions.
129 changes: 87 additions & 42 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 34 additions & 5 deletions AI.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def randomInitialize(self):
rs = randint(0, self.scheduleSize - 1)
self.schedule[rs] = (randInst, randCours)
#print(rs, randInst, randCours)
self.fitnessCalculation()

def mutate(self):
if randint(0,100)>self.mutationProbability:
Expand Down Expand Up @@ -162,6 +163,26 @@ def initChromosomes(f_numberOfNodes):
chromosomeList.append(newChro)


# Crossover (Child) of two Chromosomes
def crossover(chrom1: Chromosome, chrom2: Chromosome, f_crossoverPointNumber=8):
chromoSize = chrom1.scheduleSize
newChromo=Chromosome()
crossoverPoints = {}
while len(crossoverPoints) < f_crossoverPointNumber:
randPoint = randint(0, chromoSize-1)
if randPoint not in crossoverPoints:
crossoverPoints[randPoint] = 1
firstChoice = randint(0, 1)
for i in range(chromoSize):
if firstChoice:
newChromo.schedule[i] = chrom1.schedule[i]
else:
newChromo.schedule[i] = chrom2.schedule[i]
if i in crossoverPoints:
firstChoice = (not firstChoice)
newChromo.fitnessCalculation()
return newChromo


# Initialize Global variables
allDays = []
Expand All @@ -172,8 +193,16 @@ def initChromosomes(f_numberOfNodes):

# Start reading
readFromExcel()
initChromosomes(1)
print(len(chromosomeList))
print(chromosomeList[0].schedule)
chromosomeList[0].fitnessCalculation()
print(chromosomeList[0].scoring())

initChromosomes(100)
# print(len(chromosomeList))
# print(chromosomeList[0].schedule)
# print(chromosomeList[1].schedule)
# chrNC = crossover(chromosomeList[0],chromosomeList[1])
# print(chrNC.schedule)
# chromosomeList[0].fitnessCalculation()
# chromosomeList[1].fitnessCalculation()
# chrNC.fitnessCalculation()
# print(chromosomeList[0].scoring())
# print(chromosomeList[1].scoring())
# print(chrNC.scoring())

0 comments on commit d110857

Please sign in to comment.