一种基于启发式方法的python非线性编程API

flopt的Python项目详细描述


扑通

一个采用启发式方法的python非线性编程API。在


安装

git clone https://github.com/flab-coder/flopt.git

flopt中的公式化问题

  • 非线性问题

    ^{pr2}$ 在
  • 黑箱问题

    minimize  simulator(a, b, c)
    s.t       0 <= a <= 1
              1 <= b <= 2
              1 <= c <= 3
    
  • 寻找最佳排列问题(包括TSP)

  • 可满足性问题(包括MAX-SAT)


启发式算法

  • 随机搜索
  • 2-选项
  • 群体智能搜索
  • 其他应用

简单的例子

您可以编写类似于纸浆应用程序的代码。在

fromfloptimportVariable,Problem,Solver# Variablesa=Variable('a',lowBound=0,upBound=1,cat='Integer')b=Variable('b',lowBound=1,upBound=2,cat='Continuous')c=Variable('c',upBound=3,cat='Continuous')# Problemprob=Problem()prob+=2*(3*a+b)*c**2+3# set the objective functionprob+=a+b*c<=3# set the constraint# Solversolver=Solver(algo='ScipySearch')# select the heuristic algorithmsolver.setParams(n_trial=1000)# setting of the hyper parametersprob.solve(solver,msg=True)# run solver to solve the problem# display the result, incumbent solutionprint('obj value',prob.getObjectiveValue())print('a',a.value())print('b',b.value())print('c',c.value())

此外,您可以通过CustomExpression

fromfloptimportCustomExpressionfrommathimportsin,cosdefuser_func(a,b,c):return(0.7*a+0.3*cos(b)**2+0.1*sin(c))*abs(c)custom_obj=CustomExpression(func=user_func,variables=[a,b,c])prob=Problem(name='CustomExpression')prob+=custom_obj

在求解TSP的情况下,Permutation变量很有用。在

# Variablesperm=Variable('perm',lowBound=0,upBound=N-1,cat='Permutation')# Objectdeftsp_dist(perm):distance=0forhead,tailinzip(perm,perm[1:]+[perm[0]]):distance+=D[head][tail]# D is the distance matrixreturndistancetsp_obj=CustomExpression(func=tsp_dist,variables=[perm])# Problemprob=Problem(name='TSP')prob+=tsp_obj

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java在某些练习中避免索引异常   java Android,如何在具有socket的网络区域上提高性能?   更改web中的执行顺序后,JavaServlet过滤器不起作用。xml   java如何绑定泛型类?   JavaGmail RESTAPI:使用Google凭证而不模拟   java是解码整数序列的最快方法   java根据hashmaps的值(通过map的值进行比较)对hashmaps的数组列表进行排序   用于JBoss 7.1或Apache的java负载平衡器,带有Healt检查   java非常慢的MySQL读取性能   java如何在使用iRetryAnalyzer时从Windows CMD关闭Selenium WebDriver?   java随机闪烁仅出现在Galaxy Note 4上   java AttributeOverride MappedSuperClass属性的类型不同   java JPA:如何检测现有实体是否已更新?   java如何使用mavenassemblyplugin从dependencySet中删除METAINF?   安装SecurityManager时,java MQQueueManager构造函数挂起