Individual.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:PyGenAlg 作者: RaphDeau 项目源码 文件源码
def __generateRandomVarValue(cls, iVar):
        # 1- Get the definition domain of the variable
        defDomain = cls.VARIABLES_RANGES[iVar]
        if defDomain is None:
            randFloat = random.uniform(-sys.maxint-1, sys.maxint)
        else:
            # 2- Check the open/closed bounds
            includeFirst = defDomain[0] == '['
            includeLast = defDomain[-1] == ']'
            # 3- Get a random number in the domain
            defDomain = eval('[' + defDomain[1:-1] + ']')
            randFloat = random.random()*(defDomain[1]-defDomain[0]) + defDomain[0]
            # 4- Check the bounds
            while (randFloat == defDomain[0] and not includeFirst) or\
                    (randFloat == defDomain[1] and not includeLast):
                randFloat = random.random()*(defDomain[1]-defDomain[0]) + defDomain[0]
        # 5- Cast the variable type
        return cls.VARIABLES_TYPE(randFloat)
    # ----------------------
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号