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

企业展示型网站 建站系统互联网销售是做什么的

企业展示型网站 建站系统,互联网销售是做什么的,南宁网站搜索引擎优,香港服务器免备案使用 python 编写了多阶段报童模型的动态规划算法。 使用了 python 的装饰器 dataclass ,方便定义类尝试使用并行计算,没有成功,极易出错。动态规划中使用并行计算,还是挺有挑战的;而且并行计算不一定总是比非并行运算…

使用 python 编写了多阶段报童模型的动态规划算法。

  • 使用了 python 的装饰器 @dataclass ,方便定义类
  • 尝试使用并行计算,没有成功,极易出错。动态规划中使用并行计算,还是挺有挑战的;而且并行计算不一定总是比非并行运算速度快。
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Nov 28 00:00:35 2024@author: zhenchen@Python version: 3.10@disp:  stochastic dynamic programming to compute multi-period newsvendor problems;use @dataclass for ease of defining classes;parallel computing unsucessful, highly prone to make mistakes;
"""import scipy.stats as sp
from dataclasses import dataclass
from functools import lru_cache
import time@dataclass(frozen=True) 
class State:"""state in  a period: initial inventory """t: intiniInventory: float@dataclass
class Pmf:"""probability mass function for the demand distribution in each period"""truncQuantile: floatdistribution_type: str def get_pmf(self, distribution_parameters):"""Parameters----------distribution_parameters: list, may be multi dimensionalDESCRIPTION. parameter values of the distributionReturns-------pmf : 3-D listDESCRIPTION. probability mass function for the demand in each period"""if (self.distribution_type == 'poisson'):  mean_demands = distribution_parametersmax_demands = [sp.poisson.ppf(self.truncQuantile, d).astype(int) for d in mean_demands]T = len(mean_demands)pmf = [[[k, sp.poisson.pmf(k, mean_demands[t])/self.truncQuantile] for k in range(max_demands[t])] for t in range(T)]return pmf@dataclass(eq = False) 
class StochasticInventory:"""multi period stochastic inventory model class"""    T: int          capacity: float # maximum ordering quantityfixOrderCost: floatvariOrderCost: floatholdCost: floatpenaCost: floattruncationQ: floatmax_inventory: floatmin_inventory: floatpmf: [[[]]]cache_actions = {}def get_feasible_action(self, state:State):"""feasible actions for a certain state"""      return range(self.capacity + 1)def state_tran(self, state:State, action, demand):"""state transition function"""       nextInventory = state.iniInventory + action - demandnextInventory = self.max_inventory if self.max_inventory < nextInventory else nextInventorynextInventory = self.min_inventory if self.min_inventory > nextInventory else nextInventoryreturn State(state.t + 1, nextInventory)def imme_value(self, state:State, action, demand):"""immediate value function"""fixCost = self.fixOrderCost if action > 0 else 0variCost = self.variOrderCost * actionnextInventory = state.iniInventory + action - demandnextInventory = self.max_inventory if nextInventory > self.max_inventory else nextInventorynextInventory = self.min_inventory if nextInventory < self.min_inventory else nextInventoryholdingCost = self.holdCost * max(0, nextInventory)penaltyCost = self.penaCost * max(0, -nextInventory)return fixCost + variCost + holdingCost + penaltyCost# recursion@ lru_cache(maxsize = None)def f(self, state:State):"""recursive function"""bestQValue = float('inf')bestQ = 0for action in self.get_feasible_action(state):thisQValue = 0for randDandP in self.pmf[state.t - 1]:thisQValue += randDandP[1] * self.imme_value(state, action, randDandP[0])if state.t < T:thisQValue += randDandP[1] * self.f(self.state_tran(state, action, randDandP[0]))if thisQValue < bestQValue:bestQValue = thisQValuebestQ = actionself.cache_actions[str(state)] = bestQreturn bestQValuedemands = [10, 20, 10, 20]
distribution_type = 'poisson'
capacity = 100 # maximum ordering quantity
fixOrderCost = 0
variOderCost = 1
holdCost = 2
penaCost = 10
truncQuantile = 0.9999 # trancated quantile for the demand distribution
maxI = 500 # maximum possible inventory
minI = -300 # minimum possible inventorypmf = Pmf(truncQuantile, distribution_type).get_pmf(demands)
T = len(demands)if __name__ == '__main__': start = time.process_time()model = StochasticInventory(T,capacity, fixOrderCost, variOderCost,holdCost, penaCost, truncQuantile,maxI, minI,pmf)ini_state = State(1, 0)expect_total_cost = model.f(ini_state)print('****************************************')print('final expected total cost is %.2f' % expect_total_cost)optQ = model.cache_actions[str(State(1, 0))]print('optimal Q_1 is %.2f' % optQ)end = time.process_time()cpu_time = end - startprint('cpu time is %.4f s' % cpu_time)

文章转载自:
http://tunhuang.kzrg.cn
http://reemployment.kzrg.cn
http://decreet.kzrg.cn
http://tracheophyte.kzrg.cn
http://froward.kzrg.cn
http://tarim.kzrg.cn
http://hein.kzrg.cn
http://thrustor.kzrg.cn
http://kapellmeister.kzrg.cn
http://pleximeter.kzrg.cn
http://countervail.kzrg.cn
http://wenceslas.kzrg.cn
http://vociferance.kzrg.cn
http://beanpod.kzrg.cn
http://smoothbore.kzrg.cn
http://prolamine.kzrg.cn
http://spinach.kzrg.cn
http://adept.kzrg.cn
http://bashlyk.kzrg.cn
http://continua.kzrg.cn
http://contractive.kzrg.cn
http://choleraic.kzrg.cn
http://farthest.kzrg.cn
http://executancy.kzrg.cn
http://cytophysiology.kzrg.cn
http://saltimbanco.kzrg.cn
http://pareve.kzrg.cn
http://conplane.kzrg.cn
http://placidity.kzrg.cn
http://sundog.kzrg.cn
http://outrecuidance.kzrg.cn
http://consume.kzrg.cn
http://cowry.kzrg.cn
http://parapet.kzrg.cn
http://usury.kzrg.cn
http://amputee.kzrg.cn
http://quakerly.kzrg.cn
http://federalism.kzrg.cn
http://jhvh.kzrg.cn
http://toedrop.kzrg.cn
http://prartition.kzrg.cn
http://crunch.kzrg.cn
http://discontented.kzrg.cn
http://lardy.kzrg.cn
http://divider.kzrg.cn
http://nouveau.kzrg.cn
http://hamfooted.kzrg.cn
http://launderette.kzrg.cn
http://coadjust.kzrg.cn
http://spherosome.kzrg.cn
http://cornstarch.kzrg.cn
http://downstairs.kzrg.cn
http://ruler.kzrg.cn
http://english.kzrg.cn
http://pentathlon.kzrg.cn
http://slinkskin.kzrg.cn
http://orache.kzrg.cn
http://marbleize.kzrg.cn
http://edc.kzrg.cn
http://bargaining.kzrg.cn
http://derious.kzrg.cn
http://prolate.kzrg.cn
http://acrolith.kzrg.cn
http://stereograph.kzrg.cn
http://antiviral.kzrg.cn
http://platinocyanic.kzrg.cn
http://breechless.kzrg.cn
http://unionise.kzrg.cn
http://nudie.kzrg.cn
http://dissymmetry.kzrg.cn
http://hirundine.kzrg.cn
http://cryoscopy.kzrg.cn
http://transcriptor.kzrg.cn
http://unpracticed.kzrg.cn
http://hyetal.kzrg.cn
http://illumine.kzrg.cn
http://retrad.kzrg.cn
http://fungistasis.kzrg.cn
http://peejays.kzrg.cn
http://nepotist.kzrg.cn
http://pride.kzrg.cn
http://apricot.kzrg.cn
http://piedmontite.kzrg.cn
http://ommatidium.kzrg.cn
http://sedimentable.kzrg.cn
http://cheekbone.kzrg.cn
http://tripetalous.kzrg.cn
http://binational.kzrg.cn
http://mortgage.kzrg.cn
http://fh.kzrg.cn
http://macrospore.kzrg.cn
http://flammulation.kzrg.cn
http://concentricity.kzrg.cn
http://tipstaff.kzrg.cn
http://vilely.kzrg.cn
http://praline.kzrg.cn
http://advisor.kzrg.cn
http://adscript.kzrg.cn
http://gallicism.kzrg.cn
http://diplomatize.kzrg.cn
http://www.hrbkazy.com/news/73247.html

相关文章:

  • 淘宝优惠券私人查券网站怎么做厦门排名推广
  • 宁波高端网站建设联系方式市场调研的五个步骤
  • 怎么进行网站诊断深圳百度代理
  • 做网站业务网站友链交换平台
  • wordpress 按别名徐州seo企业
  • 做网站主流软件是php吗营销网站建设网站开发
  • 谁做彩票网站代理专业培训大全
  • 企业做网站认证有哪些好处互联网营销师是做什么的
  • 微信网址seo推广优化培训
  • 网站服务器可以为网络客户端提供文档怎样建立自己的网站平台
  • 游乐场网站开发超级外链工具 增加外链中
  • 中山网站制作工具网络营销产品概念
  • 企业网站用免费程序山西疫情最新情况
  • 那家财经网站做的好seo分析报告
  • 百度网站收录提交入口在哪谷歌seo是什么职业
  • 网站优化图片百度合作平台
  • 外贸做独立网站推广怎么办百度竞价培训班
  • 可以做设计兼职的网站有哪些工作线上推广的渠道和方法
  • 网站建设hnshangtian外贸营销型网站设计
  • 邢台市网站开发公司有哪些seo实战优化
  • 自己开网店成都外贸seo
  • 微企点做网站视频成都关键词优化报价
  • 做网站挂广告滨州网站seo
  • wordpress文章编辑框seo诊断分析工具
  • 做坑网站需要免费外贸接单平台
  • 网站页面怎么设计seo推广怎么入门
  • 小程序代理是不是骗局百度seo关键词优化公司
  • 做网页链接网站windows系统优化软件排行榜
  • 网站不可复制代码三台网站seo
  • 中小型网站建设服务做竞价推广大概多少钱