예제 #1
0
파일: main.py 프로젝트: manish211/59115ASE
def _mutateSelectivelyWithModifiedRange(xVecParam, minMaxTuple,indexP, stepParam=1):


    valToret = 0    
    xCurrent=[x for x in xVecParam]
    xBest=xVecParam
    
    listOfMax=[10, 10, 5, 6, 5, 10]
    listOfMin=[ 0,  0, 1, 0, 1,  0] 
    
    
    fractionedMax = [float(x)*float(stepParam*10)/float(100) for x in listOfMax]
    fractionedMin = [float(x)*float((stepParam*10)/100) for x in listOfMin]   
    
    #print "{}--{}".format(fractionedMax, fractionedMin)
    
    maxRangeOI = float(fractionedMax[indexP])
    minRangeOI = float(fractionedMin[indexP])
    stepOfI = maxRangeOI - minRangeOI 
    #print "stepOfI... ", stepOfI
    cnt = minRangeOI    
    run = 0     
    while cnt <= maxRangeOI:
      xCurrent[indexP] = cnt 
      if checker.checkConstraints(xCurrent):
        if calcNormEnergy(xBest, minMaxTuple) <= calcNormEnergy(xCurrent, minMaxTuple):
           xBest = [xtemp for xtemp in xCurrent]   
      cnt = cnt + stepOfI 
      run = run + 1    
    valToret = [ _ for _ in xBest]
    #print "run ..." , run
    run  = 0    
    return valToret
예제 #2
0
파일: main.py 프로젝트: sbiswas4/59115ASE
def _mutateSelectively(xVecParam, minMaxTuple, indexP, stepParam=20):
    valToret = 0
    xCurrent = [x for x in xVecParam]
    xBest = xVecParam

    listOfMax = [10, 10, 5, 6, 5, 10]
    listOfMin = [0, 0, 1, 0, 1, 0]

    #    distance=(listOfMax[indexP]-listOfMin[indexP])/stepParam
    #
    #    range1 = int((xCurrent[indexP]-listOfMin[indexP])/distance)
    #    range2 = int((listOfMax[indexP]-xCurrent[indexP])/distance)
    #    #print "r-1 {}, r-2 {},  dist = {}".format(range1, range2, distance)
    #    for cnt in range(-range1, range2+1):
    #        xCurrent[indexP]=xVecParam[indexP]+cnt*distance
    #        if not checker.checkConstraints(xCurrent):
    #           continue
    #        else:
    #          if calcNormEnergy(xBest, minMaxTuple) <= calcNormEnergy(xCurrent, minMaxTuple):
    #           xBest=xCurrent
    maxRangeOI = float(listOfMax[indexP])
    minRangeOI = float(listOfMin[indexP])
    stepOfI = float((maxRangeOI - minRangeOI) / stepParam)
    cnt = minRangeOI
    while cnt <= maxRangeOI:
        xCurrent[indexP] = cnt
        if checker.checkConstraints(xCurrent):
            if calcNormEnergy(xBest, minMaxTuple) <= calcNormEnergy(
                    xCurrent, minMaxTuple):
                xBest = [xtemp for xtemp in xCurrent]
        cnt = cnt + stepOfI
    valToret = [_ for _ in xBest]
    return valToret
예제 #3
0
파일: main.py 프로젝트: manish211/59115ASE
def _mutateSelectively(xVecParam, minMaxTuple,indexP, stepParam=20):
    valToret = 0
    xCurrent=[x for x in xVecParam]
    xBest=xVecParam

    listOfMax=[10, 10, 5, 6, 5, 10]
    listOfMin=[ 0,  0, 1, 0, 1,  0]

#    distance=(listOfMax[indexP]-listOfMin[indexP])/stepParam
#
#    range1 = int((xCurrent[indexP]-listOfMin[indexP])/distance)
#    range2 = int((listOfMax[indexP]-xCurrent[indexP])/distance)
#    #print "r-1 {}, r-2 {},  dist = {}".format(range1, range2, distance)
#    for cnt in range(-range1, range2+1):
#        xCurrent[indexP]=xVecParam[indexP]+cnt*distance
#        if not checker.checkConstraints(xCurrent):
#           continue
#        else:
#          if calcNormEnergy(xBest, minMaxTuple) <= calcNormEnergy(xCurrent, minMaxTuple):
#           xBest=xCurrent
    maxRangeOI = float(listOfMax[indexP])
    minRangeOI = float(listOfMin[indexP])
    stepOfI = float((maxRangeOI - minRangeOI)/stepParam)
    cnt = minRangeOI
    while cnt <= maxRangeOI:
      xCurrent[indexP] = cnt
      if checker.checkConstraints(xCurrent):
        if calcNormEnergy(xBest, minMaxTuple) <= calcNormEnergy(xCurrent, minMaxTuple):
           xBest = [xtemp for xtemp in xCurrent]
      cnt = cnt + stepOfI
    valToret = [ _ for _ in xBest]
    return valToret
예제 #4
0
파일: main.py 프로젝트: sbiswas4/59115ASE
def _mutateRandomly(xVecParam, indexParam):
    import baseline
    vecToUse = [_ for _ in xVecParam]
    while True:
        #vecToUse[indexParam] = random.uniform(listOfMin[indexParam], listOfMax[indexParam])
        vecToUse[indexParam] = baseline.getVariableBounds(indexParam)
        if checker.checkConstraints(vecToUse):
            break
    return vecToUse
예제 #5
0
파일: main.py 프로젝트: manish211/59115ASE
def _mutateRandomly(xVecParam, indexParam):
  import baseline
  vecToUse = [ _ for _ in xVecParam]
  while True:
   #vecToUse[indexParam] = random.uniform(listOfMin[indexParam], listOfMax[indexParam])
   vecToUse[indexParam] = baseline.getVariableBounds(indexParam)
   if checker.checkConstraints(vecToUse):
     break
  return vecToUse
예제 #6
0
def _secondObj(xVecParam):
    valToRet = 0
    if (checker.checkVariableBounds(xVecParam)):
        if (checker.checkConstraints(xVecParam)):
            for valI in xVecParam:
                valToRet = valToRet + math.pow(valI, 2)
        else:
            valToRet = float('nan')
            print "Second Objective Failed : Input vector violates Oscyzaka-II's constraints !", xVecParam
    else:
        valToRet = float('nan')
        print "Second Objective Failed : Input vector violates Oscyzaka-II's variable bounds !", xVecParam
    #print valToRet
    return valToRet
예제 #7
0
def _secondObj(xVecParam):
  valToRet = 0   
  if(checker.checkVariableBounds(xVecParam)):
    if(checker.checkConstraints(xVecParam)):
      for valI in xVecParam:  
        valToRet = valToRet + math.pow(valI, 2)
    else:
      valToRet =  float('nan')  
      print "Second Objective Failed : Input vector violates Oscyzaka-II's constraints !", xVecParam    
  else:
      valToRet =  float('nan')        
      print "Second Objective Failed : Input vector violates Oscyzaka-II's variable bounds !", xVecParam
  #print valToRet    
  return valToRet          
예제 #8
0
def _firstObj(xVecParam):
  valToRet = 0   
  if(checker.checkVariableBounds(xVecParam)):
    if(checker.checkConstraints(xVecParam)):
      factor1 = 25 * math.pow(xVecParam[0] - 2, 2)
      factor2 = math.pow(xVecParam[1] - 2, 2)
      factor3 = math.pow(xVecParam[2] - 1, 2) * math.pow(xVecParam[3] - 4, 2) 
      factor4 = math.pow(xVecParam[4] - 1, 2)
      valToRet = -1 * (factor1 + factor2 + factor3 + factor4)
    else:
      valToRet =  float('nan')  
      print "First Objective Failed : Input vector violates Oscyzaka-II's constraints !" , xVecParam   
  else:
      valToRet =  float('nan')        
      print "First Objective Failed : Input vector violates Oscyzaka-II's variable bounds !", xVecParam
  return valToRet        
예제 #9
0
def _firstObj(xVecParam):
    valToRet = 0
    if (checker.checkVariableBounds(xVecParam)):
        if (checker.checkConstraints(xVecParam)):
            factor1 = 25 * math.pow(xVecParam[0] - 2, 2)
            factor2 = math.pow(xVecParam[1] - 2, 2)
            factor3 = math.pow(xVecParam[2] - 1, 2) * math.pow(
                xVecParam[3] - 4, 2)
            factor4 = math.pow(xVecParam[4] - 1, 2)
            valToRet = -1 * (factor1 + factor2 + factor3 + factor4)
        else:
            valToRet = float('nan')
            print "First Objective Failed : Input vector violates Oscyzaka-II's constraints !", xVecParam
    else:
        valToRet = float('nan')
        print "First Objective Failed : Input vector violates Oscyzaka-II's variable bounds !", xVecParam
    return valToRet
예제 #10
0
파일: main.py 프로젝트: sbiswas4/59115ASE
def _mutateSelectivelyWithModifiedRange(xVecParam,
                                        minMaxTuple,
                                        indexP,
                                        stepParam=1):

    valToret = 0
    xCurrent = [x for x in xVecParam]
    xBest = xVecParam

    listOfMax = [10, 10, 5, 6, 5, 10]
    listOfMin = [0, 0, 1, 0, 1, 0]

    fractionedMax = [
        float(x) * float(stepParam * 10) / float(100) for x in listOfMax
    ]
    fractionedMin = [
        float(x) * float((stepParam * 10) / 100) for x in listOfMin
    ]

    #print "{}--{}".format(fractionedMax, fractionedMin)

    maxRangeOI = float(fractionedMax[indexP])
    minRangeOI = float(fractionedMin[indexP])
    stepOfI = maxRangeOI - minRangeOI
    #print "stepOfI... ", stepOfI
    cnt = minRangeOI
    run = 0
    while cnt <= maxRangeOI:
        xCurrent[indexP] = cnt
        if checker.checkConstraints(xCurrent):
            if calcNormEnergy(xBest, minMaxTuple) <= calcNormEnergy(
                    xCurrent, minMaxTuple):
                xBest = [xtemp for xtemp in xCurrent]
        cnt = cnt + stepOfI
        run = run + 1
    valToret = [_ for _ in xBest]
    #print "run ..." , run
    run = 0
    return valToret
예제 #11
0
파일: tester.py 프로젝트: sbiswas4/59115ASE
def test_c_checkoscyzaka2_obj2():
    vecToTest = [-5.5, 2, 3, 3, 1, -1.9]
    assert False==checker.checkVariableBounds(vecToTest)
    assert False==checker.checkConstraints(vecToTest)   
    assert True==math.isnan(oscyzaka2._secondObj(vecToTest))
예제 #12
0
파일: tester.py 프로젝트: sbiswas4/59115ASE
def test_a_checkoscyzaka2_obj2():
    vecToTest = [1, 2, 3, 3, 3, 9]
    assert True==checker.checkVariableBounds(vecToTest)
    assert True==checker.checkConstraints(vecToTest)   
    assert 113==oscyzaka2._secondObj(vecToTest)
예제 #13
0
파일: tester.py 프로젝트: sbiswas4/59115ASE
def test_c_checkoscyzaka2_obj1():
    vecToTest = [1.0, 2.0, 3.0, 3.0, 3.0, 9.0]
    assert True==checker.checkVariableBounds(vecToTest)
    assert True==checker.checkConstraints(vecToTest)   
    assert -33==oscyzaka2._firstObj(vecToTest)          
예제 #14
0
파일: tester.py 프로젝트: sbiswas4/59115ASE
def test_b_checkoscyzaka2_obj1():
    vecToTest = [0, 2, 3, 3, 1, 9]
    assert True==checker.checkVariableBounds(vecToTest)
    assert False==checker.checkConstraints(vecToTest)   
    assert True==math.isnan(oscyzaka2._firstObj(vecToTest))         
예제 #15
0
파일: tester.py 프로젝트: sbiswas4/59115ASE
def test_a_checkoscyzaka2_obj1():
    vecToTest = [1, 2, 3, 3, 3, 9]
    assert True==checker.checkVariableBounds(vecToTest)
    assert True==checker.checkConstraints(vecToTest)   
    assert -33==oscyzaka2._firstObj(vecToTest)         
예제 #16
0
파일: tester.py 프로젝트: sbiswas4/59115ASE
def test_c_checkConstraints():
    vecToTest = [0, 2, 3, 3, 1, 9]
    assert True==checker.checkVariableBounds(vecToTest)
    assert False==checker.checkConstraints(vecToTest)   
예제 #17
0
파일: tester.py 프로젝트: sbiswas4/59115ASE
def test_b_checkConstraints():
    vecToTest = [-1, 2, 3, 3, 3, 9]
    assert False==checker.checkVariableBounds(vecToTest)
    assert False==checker.checkConstraints(vecToTest)        
예제 #18
0
파일: tester.py 프로젝트: sbiswas4/59115ASE
def test_a_checkConstraints():
    vecToTest = [1, 2, 3, 3, 3, 9]
    assert True == checker.checkVariableBounds(vecToTest)
    assert True==checker.checkConstraints(vecToTest)        
예제 #19
0
def getValidVector():
  vec =  [getVariableBounds(0), getVariableBounds(1), getVariableBounds(2), getVariableBounds(3), getVariableBounds(4), getVariableBounds(5)]
  while not checker.checkConstraints(vec):
    vec =  [getVariableBounds(0), getVariableBounds(1), getVariableBounds(2), getVariableBounds(3), getVariableBounds(4), getVariableBounds(5)]

  return vec