只为小站
首页
域名查询
文件下载
登录
分支限界
法解决装载问题
分支限界
法解决装载问题 C++实现。
分支限界
法类似于回溯法,也是一种在问题的解空间树T中搜索问题解的算法。
2022-12-13 18:09:09
66KB
装载问题
分支限界
1
中科大 算法导论 课件(全套12)
分支限界
法
中国科学技术大学 算法导论 课件 计算机相关专业必修
2022-11-06 23:53:36
629KB
中科大
算法导论
课件
1
算法分析题6-4和n皇后优先队列式
分支限界
法.pdf
算法分析题6-4和n皇后优先队列式
分支限界
法.pdf
2022-07-10 09:13:44
367KB
文档资料
分支限界
单源最短路径
采用广度优先产生状态空间树的结点,并使用剪枝函数的方法称为分枝限界法。在下图所给的有向图G中,每一边都有一个非负边权。要求图G的从源顶点s到目标顶点t之间的最短路径。
2022-06-26 13:52:19
73KB
单源最短路径
1
分支限界
法求解TSP问题程序设计说明书.doc
分支限界
法求解TSP问题程序设计说明书
2022-06-18 19:05:16
105KB
文档资料
分支限界
法 装载问题
#include
#include
#include
#include
using namespace std; ifstream infile; ofstream outfile; class Node { friend int func(int*, int, int, int*); public: int ID; double weight;//物品的重量 }; bool comp1(Node a, Node b) //定义比较规则 { return a.weight > b.weight; } class Load; class bbnode; class Current { friend Load; friend struct Comp2; private: int upweight;//重量上界 int weight;//结点相应的重量 int level;//活结点在子集树中所处的层次 bbnode* ptr;//指向活结点在子集树中相应结点的指针 }; struct Comp2 { bool operator () (Current *x, Current *y) { return x->upweight
upweight; } }; class Load { friend int func(int*, int, int, int*); public: int Max0(); private: priority_queue
, Comp2>H;//利用优先队列(最大堆)储存 int limit(int i); void AddLiveNode(int up, int cw, bool ch, int level); bbnode *P;//指向扩展结点的指针 int c;//背包的容量 int n;//物品的数目 int *w;//重量数组 int cw;//当前装载量 int *bestx;//最优解方案数组 }; class bbnode { friend Load; friend int func( int*, int, int, int*); bbnode* parent; bool lchild; }; //结点中有双亲指针以及左儿子标志 int Load::limit(int i) //计算结点所相应重量的上界 { int left,a; left= c - cw;//剩余容量 a = cw; //b是重量上界,初始值为已经得到的重量 while (i <= n && w[i] <= left) { left -= w[i]; a += w[i]; i++; } return a; } void Load::AddLiveNode(int up, int cw, bool ch, int level) //将一个新的活结点插入到子集树和优先队列中 { bbnode *b = new bbnode; b->parent = P; b->lchild = ch; Current* N = new Current; N->upweight = up; N->weight = cw; N->level = level; N->ptr = b; H.push(N); } int Load::Max0() { int i = 1; P = 0; cw = 0; int bestw = 0; int up = limit(1); while (i != n + 1) { int wt = cw + w[i]; //检查当前扩展结点的左儿子结点 if (wt <= c)//左儿子结点是可行结点 { if (wt > bestw) bestw =wt; AddLiveNode(up,wt, true, i + 1); } up = limit(i + 1); //检查当前扩展结点的右儿子结点 if (up >= bestw)//如果右儿子可行 { AddLiveNode(up,cw, false, i + 1); } Current* N = H.top(); //取队头元素 H.pop(); P = N->ptr; cw = N->weight; up = N->upweight; i = N->level; } bestx = new int[n + 1]; for (int j = n; j > 0; --j) { bestx[j] = P->lchild; P = P->parent; } return cw; } int func(int *w, int c, int n, int *bestx) //调用Max0函数对子集树的优先队列式进行
分支限界
搜索 { int W = 0; //初始化装载的总质量为0 Node* Q = new Node[n]; for (int i = 0; i < n; ++i) { Q[i].ID = i + 1; Q[i].weight = w[i+1]; W += w[i+1]; } if (W <= c)//如果足够装,全部装入 return W; sort(Q, Q + n, comp1); //首先,将各物品按照重量从大到小进行排序; Load K; K.w = new int[n + 1]; for (int j = 0; j < n; j++) K.w[j + 1] = w[Q[j].ID]; K.cw = 0; K.c = c; K.n = n; int bestp = K.Max0(); for (int k = 0; k < n; k++) { bestx[Q[k].ID] = K.bestx[k + 1]; } delete []Q; delete []K.w; delete []K.bestx; return bestp; } int main() { int*w,*Final; int c,n,i,best; infile.open("input.txt",ios::in); if(!infile) { cerr<<"open error"<
>c; infile>>n; w=new int[n+1]; for(i=1;i<=n;i++) infile>>w[i]; infile.close(); Final = new int[n+1]; best = func( w, c, n, Final); outfile.open("output.txt",ios::out); if(!outfile) { cerr<<"open error"<
2022-06-07 18:10:13
4KB
分支限界
1
算法设计与分析-第9讲
分支限界
法.ppt
算法设计与分析-第9讲
分支限界
法.ppt
2022-05-30 19:07:11
776KB
算法
文档资料
分支限界
算法的研究与实现.doc
分支限界
算法的研究与实现.doc
2022-05-30 09:08:31
29KB
算法
文档资料
算法设计与分析习题第六章
分支限界
法.ppt
算法设计与分析习题第六章
分支限界
法.ppt
2022-05-27 14:08:17
41KB
文档资料
算法
cpp代码-
分支限界
法求解0-1背包问题
cpp代码-
分支限界
法求解0-1背包问题
2022-05-26 23:57:09
2KB
代码
1
个人信息
点我去登录
购买积分
下载历史
恢复订单
热门下载
安卓开发期末大作业----单词本(源码,任务书,大报告,apk文件)(基于andord studio)
RNN-LSTM卷积神经网络Matlab实现
python大作业--爬虫(完美应付大作业).zip
2020年大学生数学建模竞赛C题省一论文(包括材料和代码)
Microsoft Visual C++ 2015-2019 运行库合集,包含32位64位
王万良-人工智能导论(第五版)课件
刚萨雷斯《数字图像处理》第四版答案.pdf
quartus II13.0器件库.zip
DS证据理论的MATLAB案例程序源代码
知网情感词典(HOWNET)
MATLAB车牌识别系统
token登录器.rar
EBSD分析软件——Channel5下载安装教程
Academic+Phrasebank+2021+Edition+_中英文对照.pdf
VideoDownloadHelper去除120分钟时间限制-高级版.zip
最新下载
30多个无线天线pcb封装库2.4G WIFI 蓝牙 GPS GMS 433MHZ 天线封装库ALTIUM AD库大集合
spconv-1.2.1-cp37-cp37m-linux_x86_64.whl下载
基于有源阻尼法的LCL型并网逆变器Simulink仿真模型
数学建模 原料钢管下料的非线性优化模型
wigb函数(matlab中画地震剖面用)
西门子OPC UA官方示例程序源代码
模式识别4个实验(matlab)
Parallels Workstation (Extreme)6.0 算号器
地震成像裂步Fourier法/split-step Fourier脉冲响应
三相逆变器及simulink仿真
其他资源
verilog实现OFDM程序(全)
IBM i2 Analyst's Notebook 快速入门指南(中文版)
KeyCleanerv1.4(psp key修复)
AD封装库 + 3D模型 最全
郭天祥的GSM与51单片机通信程序一
JSP+MYSQL学生个人理财系统-毕业设计
中国科学技术大学计算机图形学大作业
引物设计Primer Premier 5 64位系统
合成大西瓜源码.zip
中文版VC++6.0(64bit)
Logmein Hamachi
星火英语1~6级 是一个学习英语的不错资料,用它你可以更好地念单词
Mastering your PhD
计算器.zip
好用的U盘格式化工具FormatTool
Linux实验四shell编程
DELL机架式服务器最新Viso模具
待办事项APP
华为Verilog编程规范
计算机图形学课设,线画图元生成系统
51单片机,电子琴程序,原理图