当前位置: 首页 > wzjs >正文

电信网站备案流程图国家企业信用信息公示系统下载

电信网站备案流程图,国家企业信用信息公示系统下载,wordpress媒体库制作文件夹,安装网站程序的流程之前在 FastAPI介绍-CSDN博客 中介绍过FastAPI,在 Pyomo中线性规划接口的使用-CSDN博客 中使用Pyomo解决饮食问题,这里将两者组合,即FastAPI在服务器端启动,通过Pyomo实现线性回归;客户端通过浏览器获取饮食的最优解。…

      之前在 FastAPI介绍-CSDN博客 中介绍过FastAPI,在 Pyomo中线性规划接口的使用-CSDN博客  中使用Pyomo解决饮食问题,这里将两者组合,即FastAPI在服务器端启动,通过Pyomo实现线性回归;客户端通过浏览器获取饮食的最优解。

      这里服务器端的diet.json是已存在的,后期调整为从客户端传过来,以及其它可变参数也从客户端通过json格式传给服务器端。

      实现如下:

from fastapi import FastAPI
from pyomo.environ import *
import mathdef parse_json(file):model = ConcreteModel()data = DataPortal()data.load(filename=file)model.F = Set(initialize=data['sets']['F'])model.N = Set(initialize=data['sets']['N'])model.c = Param(model.F, initialize=data['params']['c'], within=PositiveReals)def parse_a(model, food, nutr):return data['params']['a'][food][nutr]model.a = Param(model.F, model.N, initialize=parse_a, within=NonNegativeReals)model.V = Param(model.F, initialize=data['params']['V'], within=PositiveReals)model.Nmin = Param(model.N, initialize=data['params']['Nmin'], within=NonNegativeReals, default=0.0)def parse_Nmax(model, nutr):val = data['params']['Nmax'][nutr]return val if val != "inf" else math.inf model.Nmax = Param(model.N, initialize=parse_Nmax, within=NonNegativeReals)model.Vmax = Param(initialize=data['params']['Vmax'], within=PositiveReals)return modeldef linear_programming_diet(file, number):model = parse_json(file)model.x = Var(model.F, within=NonNegativeIntegers)model.y = Var(model.F, within=Binary)model.cost = Objective(expr=sum(model.c[i]*model.x[i] for i in model.F), sense=minimize)def nutrient_rule(model, j):value = sum(model.a[i,j]*model.x[i] for i in model.F)return inequality(model.Nmin[j], value, model.Nmax[j])model.nutrient_limit = Constraint(model.N, rule=nutrient_rule)def volume_rule(model):return sum(model.V[i]*model.x[i] for i in model.F) <= model.Vmaxmodel.volume = Constraint(rule=volume_rule)def select_rule(model):return sum(model.y[i] for i in model.F) == numbermodel.select = Constraint(rule=select_rule)def linking_upper_rule(model, f):return model.x[f] <= model.y[f] * 1e6model.linking_upper = Constraint(model.F, rule=linking_upper_rule)def linking_lower_rule(model, f):return model.x[f] >= model.y[f]model.linking_lower = Constraint(model.F, rule=linking_lower_rule)solver = SolverFactory('glpk')results = solver.solve(model)if results.solver.termination_condition != TerminationCondition.optimal:return {"result":"no optimal solution"}results = {}results["total const"] = f"{value(model.cost):.2f}"foods = {}count = 0for f in model.F:v = int(value(model.x[f]))if v != 0:foods[f] = vcount += 1results["selected food"] = foodsif count != number:return {"result":"solution result is wrong, number of food types does not match"}nutrients = {}	for n in model.N:actual = sum(value(model.a[f,n] * model.x[f]) for f in model.F)nutrients[n] = f"{actual:.2f}"results["nutrients"] = nutrientsreturn resultsapp = FastAPI()@app.get("/diet")
def diet_optimization():return linear_programming_diet("../test_data/diet.json", 5)

      通过以下命令启动:

fastapi dev test_fastapi_pyomo.py

      在浏览器中输入:http://127.0.0.1:8000/diet ,结果如下图所示:

      GitHub:https://github.com/fengbingchun/Python_Test


文章转载自:

http://FI6ogMlr.bfhfb.cn
http://bzWHf2kU.bfhfb.cn
http://oPz64Wql.bfhfb.cn
http://fc7tAqBN.bfhfb.cn
http://2g4gOuJE.bfhfb.cn
http://inalLuy7.bfhfb.cn
http://dSsK4rov.bfhfb.cn
http://9bLDPAII.bfhfb.cn
http://z168Rcx1.bfhfb.cn
http://p1Swv1Cc.bfhfb.cn
http://BXaqq8Qg.bfhfb.cn
http://gq6diEb8.bfhfb.cn
http://P0SwIu5r.bfhfb.cn
http://mSbsG637.bfhfb.cn
http://1IV2gMBv.bfhfb.cn
http://ucEsYuzS.bfhfb.cn
http://PVkoG1yZ.bfhfb.cn
http://QebreyZG.bfhfb.cn
http://s1hjahQ2.bfhfb.cn
http://S4ZYRyga.bfhfb.cn
http://x5IMjcft.bfhfb.cn
http://xF3b5dt4.bfhfb.cn
http://le42zCRz.bfhfb.cn
http://KCP1umBU.bfhfb.cn
http://mDP2wadv.bfhfb.cn
http://DZwJ6FQ8.bfhfb.cn
http://HIGqbKct.bfhfb.cn
http://EMYZvZFh.bfhfb.cn
http://BLGL4dN2.bfhfb.cn
http://igg9ZlEs.bfhfb.cn
http://www.dtcms.com/wzjs/723666.html

相关文章:

  • 网站建设与管理内容菏泽网站备案拍照
  • php网站源代码简述网站规划的主要内容
  • 新注册公司网站建设网站建设与维护百度百科
  • 优秀网站设计要素设计本装修
  • 网站备案号被注销每个城市建设规划在哪个网站
  • 倒计时网站模板网站的pdf预览是怎么做的
  • 网站规划的意义wordpress 带分页的主题
  • 视频网站怎么做网站引流长沙旅游攻略必去的十大景点
  • 宁夏网站建设公司公司运营计划书怎么写
  • 安徽建筑大学学工在线网站传奇 网页游戏排行榜
  • 在凡科上做的网站无法加载出来青岛模板化网站
  • 微信公众号做视频网站吗开发邦app
  • 网站和网络建设调研情况一个网站的建立需要什么
  • 做网站用html好还是vue好大型门户网站的建设外包在本公司制作好还是
  • 韶关房地产网站建设上海网页制作服务公司
  • f型网站网络推广公司外包
  • dw自己做的网站手机进不去网站左侧悬浮导航代码
  • 网站建设亿金手指科杰上海企业建站公司哪家好
  • 凡科平台网站怎么建设专业云南做网站
  • 余姚建设公司网站杭州网站开发平均工资
  • 公司商业网站怎么做我公司让别人做网站了怎么办
  • 莆田外贸网站建设有哪些凯里网站开发gzklyy
  • 旅游景区网络营销案例昆明seo外包
  • 百度推广手机网站jsp网站开发流程
  • 南海网站智能推广重庆室内设计公司
  • 怎么做刷会员网站温州论坛大罗山
  • 宁波做网站多少钱线上商城简介
  • 做视频网站服务器配置新东方在线教育平台官网
  • 电子商务网站建设调查问卷宁波网站建设哪个公司好
  • 推广型网站制作公司做歌手的网站