예제 #1
0
    def start(self,calibrationvars, objectivevars, env, calibration):
        pycalimero.log("Start TemplateAlgorithm",pycalimero.Standard)
        
        for i in range(0,int(self.getValueOfParameter("max iterations"))):
            #pycalimero.log("Run iteration",pycalimero.LogLevel.standard)
            if (pycalimero.execIteration(calibrationvars) == False):
                pycalimero.log("TemplateAlgorithm stoped by user",pycalimero.Standard)
                return True

            pycalimero.barrier()
            #pycalimero.log("Finish iteration",pycalimero.LogLevel.standard)
            
        pycalimero.log("TemplateAlgorithm DONE",pycalimero.Standard)
        return True
예제 #2
0
 def bruteforcesearch(self, calibrationvars, currentvar, env):
     var = calibrationvars[currentvar]
     
     for currentvalue in frange(var.min,var.max,var.step) + [var.max]:
         result = pycalimero.doublevector()
         result.append(currentvalue)
         var.setValues(result)
     
         if (currentvar==(calibrationvars.__len__()-1)):
             if (pycalimero.execIteration(calibrationvars) == False):
                 pycalimero.log("BruteForceSearch_P stoped by user",pycalimero.Standard)
                 return False
         else:
             if(self.bruteforcesearch(calibrationvars,currentvar+1,env)==False):
                 return True
         
     return True
예제 #3
0
def objf(x):
    xpars = array([], float32)
    calibrationvars = None
    calibration = None
    objectivevars = None
    env = None
    global error
    global baseevo
    global maxerror
    global minimize
    global alg

    if error:
        alg.maxEvaluations = 1
        return maxerror

    if isinstance(x, Evolvable):
        xpars = x.x
        calibrationvars = x.calibrationvars
        calibration = x.calibration
        objectivevars = x.objectivevars
        env = x.env
    else:
        xpars = x
        calibrationvars = baseevo.calibrationvars
        calibration = baseevo.calibration
        objectivevars = baseevo.objectivevars
        env = baseevo.env

    for index, value in enumerate(xpars):
        correctvalue = max(
            calibrationvars[index].min,
            min(calibrationvars[index].max, floor(value / calibrationvars[index].step) * calibrationvars[index].step),
        )
        currentvalue = pycalimero.doublevector()
        currentvalue.append(double(correctvalue))
        calibrationvars[index].setValues(currentvalue)

    if error:
        return maxerror

    if not pycalimero.execIteration(calibrationvars):
        error = True
        return maxerror
    else:
        pycalimero.barrier()

    result = 0.0
    resultindex = calibration.getNumOfComplete() - 1
    iterationresult = calibration.getIterationResults()[resultindex]

    for opar in objectivevars:
        result = result + sum(iterationresult.getResults(opar.getName()))

    if minimize and (result < maxerror):
        pycalimero.log("Algorithm reached maximal error", pycalimero.Standard)
        alg.maxEvaluations = 1
        return maxerror

    if (not minimize) and result > maxerror:
        pycalimero.log("Algorithm reached maximal error", pycalimero.Standard)
        alg.maxEvaluations = 1
        return maxerror
    return result