Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
madmax3000 committed Apr 14, 2020
1 parent 7220d3e commit 22239a4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

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

2 changes: 1 addition & 1 deletion .idea/pycharm-git.iml

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

2 changes: 2 additions & 0 deletions gv.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
bigout=[]#the big matrix of output targets to be achieved
bigvect=[]
bigconst=[]
hardconstraint=[]
constraintfinal=[]
counter=0#debugging
l=[]#list which stores the samples produced during timeperiod t1
n3=0#for signal selector
Expand Down
21 changes: 17 additions & 4 deletions mainframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ def initalization():
outer.append(pos-1)
ole=input("Enter the max and min limits of the output in the following format \n ( max,min)")
ole =ole.split(",")#ole is a list of max and min values
gv.hardconstraint.append(float(ole[0]))
gv.hardconstraint.append(float(ole[1]))
me=(float(ole[0])+float(ole[1]))/2
outer.append(me)
outer.append(2.5)#dummmy value to store future values
Expand All @@ -78,7 +80,10 @@ def initalization():
kooper.append(kup2)
gv.bigconst.append(kooper)
if (gv.vector==0):
ga(variables, outpu) # call genetic algorithm
lil = len(gv.hardconstraint)
for nu in range(lil):
gv.constraintfinal.append(0)
ga(variables, outpu , lil) # call genetic algorithm
return

#-----------------------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -163,7 +168,10 @@ def evaluator(vars):
print(" the ",n,"th objective error is",a)
print(" the ", n, "th objective current value is", gv.bigout[n][4])
lis.append(a) # returns result out put to genetic algorithm
return lis
for n in range(0, len(gv.bigout)):
gv.constraintfinal[2*n] = gv.bigout[n][4]-gv.hardconstraint[2*n]
gv.constraintfinal[2 * n +1] = gv.bigout[n][4] - gv.hardconstraint[2 * n + 1]
return lis,gv.constraintfinal
if gv.constraint == 'y':
coco=[]
for kio in range(len(gv.bigconst)):
Expand All @@ -178,11 +186,11 @@ def evaluator(vars):


#-------------------------------------------------------------------------------------------------------------------------------------------
def ga(variables, outpu):#genetic algorithm function
def ga(variables, outpu ,lil ):#genetic algorithm function
if gv.vector==0:
gv.algo=int(input("Enter the no: of iterations\nuser input: "))
if gv.constraint == "n":
problem = Problem(variables, outpu)
problem = Problem(variables, outpu , lil)# incoparate the constraint
if gv.constraint == "y":
problem = Problem(variables, outpu,len(gv.bigconst)) # specify the no of objectives and inputs
for i in range(0, len(gv.bigres)):
Expand All @@ -193,6 +201,11 @@ def ga(variables, outpu):#genetic algorithm function
problem.constraints[i:i + 1] = "<=0" #constraint assigning
elif gv.bigconst[i][j] == 2:
problem.constraints[i:i + 1] = ">=0"
for k in range(len(gv.hardconstraint)):
if (k % 2 == 0):
problem.constraints[k:k + 1] = "<=0"
else:
problem.constraints[k:k + 1] = ">=0"
problem.function = evaluator # call the simulator
v_population_size = 10
init_pop = [Solution(problem) for i in range(v_population_size)]
Expand Down

0 comments on commit 22239a4

Please sign in to comment.