装载问题--队列式分支界限法
来源:互联网 发布:2017淘宝竞争环境分析 编辑:程序博客网 时间:2024/06/05 06:45
include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
typedef struct Node{
int weight;
struct Node *parent;
bool choice;
}Node;
const int n = 10;
const int c= 0;
int w[n+1] = {0};
int bestx[n+1] = {0};
int bestw = 0;
queue<Node*> que;
Node *best_node = NULL;
void initParament()
{
}
void EnQueue(int i, int wt, Node *parent, bool choice)
{
if( i == n){
if( wt == bestw ){
best_node = parent;
bestx[n] = choice;
}
return;
}
Node *node = NULL;
node = new Node;
node->weight = wt;
node->parent = parent;
node->choice = choice;
que.push(node);
}
void maxLoading()
{
Node *current = 0;
int i = 1;
int current_weight = 0;
int rw = 0;
for(int i=2; i<=n; i++){
rw += w[i];
}
que.push(0);
while(true){
int wt = current_weight + w[i];
if( wt <= c ){
bestw = max(bestw, wt);
EnQueue(i, wt, current, true);
}
if( current_weight + rw > bestw ){
EnQueue(i, current_weight, current, false);
}
current = que.front();
que.pop();
if( current == NULL ){
if( que.empty() ){
break;
}
que.push(0);
current = que.front();
que.pop();
current_weight = current->weight;
rw -= w[i];
i++;
}
}
for(int i=n-1; i>=0; i++){
bestx[i] = best_node->choice;
best_node = best_node->parent;
}
}
int main()
{
initParament();
maxLoading();
return 0;
}
- 装载问题--队列式分支界限法
- 装载问题--优先队列式分支界限法
- 队列式分支界限法之装载问题
- 优先队列式分支界限法之装载问题
- 布线问题--队列式分支界限法
- 最大团问题--优先队列式分支界限法
- 优先队列式分支界限法之01背包问题
- 背包问题-优先对列式分支界限法
- 最短路径--优先队列式分支界限法
- 装载问题 队列分支限界发
- (Java)分支界限法求解背包问题
- 分支界限法 任务分配问题
- 分支界限法 旅行商问题
- 分支界限法
- 分支界限法
- 分支界限法
- 分支界限法
- 分支界限法
- Struts1.x开发流程小例子
- j2me 坦克游戏
- SQL*PLUS命令的使用大全
- 未能找到元数据文件
- j2me 图片处理大全
- 装载问题--队列式分支界限法
- RGB 256色颜色表
- poj 2100 gravedyard design 还是wa了,那位大牛看了,帮我改一下我的邮箱是972997012@qq.com
- 09年软考系统分析师考试心得
- 把问题推回去
- 实战springmodules common validator
- 联发科智能手机无法引爆山寨潮
- 化妆品行业的本质图解
- 用SQL语句添加删除修改字段