资源简介
python+cplex进行网络规划,代码简单清晰,适合初学者学习,修改参数后可直接使用
代码片段和文件信息
import subprocess
“““
Cosc364 Assignment 2: Flow Planning
Jessica Slaney Harrigan Davenport
31/05/2017
“““
def create_cplex_string(paths source_links dest_links u_num):
“““Creates the text for a minimization problem solvable by CPLEX.
The returned string is formatted to be inserted into a blank
LP file such that it is readable by CPLEX.“““
# Initialize all strings so they can added to in iterations
demand_flow_string = “\n“ # The demand flow over each path
equal_share_of_flow_string = “Equal Flow:\n“ # Constraints such that the flow is equal over paths used in parallel
capacities_string = “Capacities:\n“ # Constraints such that the flow is restricted to capacity per link
bounds_string = ““ # Bounds such that variables are non negative
binary_string = ““ # Those variables which should be restricted to {0 1}
path_number_string = “Number of Flows per Route:\n“ # There are a specific number of paths used to get to a destination
load_balance_string = “Balance That Load!:\n“ # Constraints such that the load is balanced on transit nodes using auxiliary variable r
for path in paths.keys():
flow_string = ““ # temporary variables to be iterated over and added to
path_string = ““
for variable demand_volume in paths[path]: # For every decision variable required for this path
u = “u“ + ““.join(list(variable)[1:]) # Describes whether the path is used or not
flow_string += “{} + “.format(variable)
path_string += “{} + “.format(u)
binary_string += “{} “.format(u)
equal_share_of_flow_string += “{} {} - {} {} = 0\n“.format(u_num variable demand_volume u)
bounds_string += “{} >= 0\n“.format(variable)
load_balance_string += “{} - r <= 0\n“.format(variable)
# Add decision variable constraints/bounds created so far to their relevant strings
flow_string = ““.join(list(flow_string)[:-2]) + “= {}\n“.format(demand_volume)
demand_flow_string += flow_string
path_string = ““.join(list(path_string)[:-3]) + “ = {}\n“.format(u_num)
path_number_string += path_string
# Restrain the decision variable values in terms of link capacity from source to transit node
for c in source_links.keys():
cap_string = ““
for variable in source_links[c]:
cap_string += “{} + “.format(variable)
cap_string = ““.join(list(cap_string)[:-2]) + “- {} <= 0\n“.format(c)
capacities_string += cap_string
bounds_string += “{} >= 0\n“.format(c)
# Restrain the decision variable values in terms of link capacity from transit to destination node
for d in dest_links.keys():
cap_string = ““
for variable in dest_links[d]:
cap_string += “{} + “.format(variable)
cap_string = ““.join(list(cap_string)[:-2]) + “- {} <= 0\n“.format(d)
capacities_string += cap_string
bounds_string += “{} >= 0\n“.f
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-08-06 14:50 networing_assignment_route_planning-master\
文件 6481 2017-05-31 09:11 networing_assignment_route_planning-master\cosc364_ass_2.py
文件 3802 2018-08-06 14:50 networing_assignment_route_planning-master\cplex.log
目录 0 2018-06-04 19:49 networing_assignment_route_planning-master\cplexPy-master\
文件 203 2018-01-03 05:29 networing_assignment_route_planning-master\cplexPy-master\README.md
目录 0 2018-06-04 19:49 networing_assignment_route_planning-master\cplexPy-master\lshaped\
目录 0 2018-06-04 19:49 networing_assignment_route_planning-master\cplexPy-master\lshaped\farmer\
文件 86 2018-01-03 05:29 networing_assignment_route_planning-master\cplexPy-master\lshaped\farmer\master.lp
文件 17 2018-01-03 05:29 networing_assignment_route_planning-master\cplexPy-master\lshaped\farmer\scenario.dat
文件 188 2018-01-03 05:29 networing_assignment_route_planning-master\cplexPy-master\lshaped\farmer\subproblem1.lp
文件 188 2018-01-03 05:29 networing_assignment_route_planning-master\cplexPy-master\lshaped\farmer\subproblem2.lp
文件 188 2018-01-03 05:29 networing_assignment_route_planning-master\cplexPy-master\lshaped\farmer\subproblem3.lp
文件 13569 2018-01-03 05:29 networing_assignment_route_planning-master\cplexPy-master\lshaped\lshaped.py
文件 1887 2018-01-03 05:29 networing_assignment_route_planning-master\cplexPy-master\lshaped\main.py
文件 73 2018-01-03 05:29 networing_assignment_route_planning-master\cplexPy-master\lshaped\master.lp
文件 23 2018-01-03 05:29 networing_assignment_route_planning-master\cplexPy-master\lshaped\scenario.dat
文件 188 2018-01-03 05:29 networing_assignment_route_planning-master\cplexPy-master\lshaped\subproblem1.lp
文件 188 2018-01-03 05:29 networing_assignment_route_planning-master\cplexPy-master\lshaped\subproblem2.lp
文件 188 2018-01-03 05:29 networing_assignment_route_planning-master\cplexPy-master\lshaped\subproblem3.lp
文件 188 2018-01-03 05:29 networing_assignment_route_planning-master\cplexPy-master\lshaped\subproblem4.lp
文件 4138 2018-08-06 14:50 networing_assignment_route_planning-master\output.txt
文件 2709 2018-08-06 14:50 networing_assignment_route_planning-master\tm.lp
相关资源
- python实现SGBM图像匹配算法
- python实现灰度直方图均衡化
- scrapy_qunar_one
- Python学习全系列教程永久可用
- python简明教程.chm
- 抽奖大转盘python的图形化界面
- 双边滤波器实验报告及代码python
- python +MYSQL+HTML实现21蛋糕网上商城
- Python-直播答题助手自动检测出题搜索
- OpenCV入门教程+OpenCV官方教程中文版
- Python 串口工具源码+.exe文件
- Python开发的全栈股票系统.zip
- Python操作Excel表格并将其中部分数据写
- python书籍 PDF
- 利用python绘制散点图
- python+labview+No1.vi
- 老男孩python项目实战
- python源码制作whl文件.rar
- python3.5可用的scipy
- PYTHON3 经典50案例.pptx
- 计算机科学导论-python.pdf
- python模拟鼠标点击屏幕
- windows鼠标自动点击py脚本
- 鱼c小甲鱼零基础学python全套课后题和
- Python 练习题100道
- Practical Programming 2nd Edition
- wxPython Application Development Cookbook
- python 3.6
- Python 3.5.2 中文文档 互联网唯一CHM版本
- python3.5.2.chm官方文档
评论
共有 条评论