资源简介
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试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
评论
共有 条评论