Ejemplo n.º 1
0
 def start(self,calibrationvars, objectivevars, env, calibration):
     pycalimero.log("Start BruteForceSearch_P",pycalimero.Standard)
     result =  self.bruteforcesearch(calibrationvars,0,env)
     pycalimero.barrier()
     pycalimero.log("BruteForceSearch_P DONE",pycalimero.Standard)
     
     return result;
Ejemplo n.º 2
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
Ejemplo n.º 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