資源簡介
在箱子裝載問題中,有若干個容量為c的箱子和n個待裝載入箱子中的物品。物品i需占是s[i]個單元(0<s[i]n依次取100,200,500,1000,比較以上四種方法(在時間上和所用箱子的數量上)的性能。
->FF,FFD方法使用競賽樹結構,BF,BFD使用AVL樹結構。

代碼片段和文件信息
#pragma?once
#include?“AVLTree.h“
#include?“AVLTreeNode.h“
#include?“binType.h“
#include?
#include??“completeWinnerTree.h“
#include?
#include?
#include?“dBinarySearchTreeWithGE.h“
using?namespace?std;
void?select_sort(int?*array?int?n)
{
int?i?j?t;
for?(i?=?1;?i {
for?(j?=?i?+?1;?j {
if?(array[j]?>?array[i])
{
t?=?array[j];
array[j]?=?array[i];
array[i]?=?t;
}
}
}
}
void?firstFitPack(int?*objectSize?int?numberOfobjects?int?binCapacity)
{//輸出箱子容量為binCapacity的最先適配裝載
?//objectSize[1:numberOfobjects]是物品大小
?//初始化一個放箱子編號的數組
int?n?=?numberOfobjects;
int?*number?=?new?int[n?+?1];
//初始化n個箱子和贏者樹
binType?*bin?=?new?binType[n?+?1];??????//箱子
for?(int?i?=?1;?i?<=?n;?i++)
bin[i].unusedCapacity?=?binCapacity;?//箱子的剩余容量
completeWinnerTree?winTree(bin?n);
//將物品裝到箱子里
for?(int?i?=?1;?i?<=?n;?i++)
{//把物品i裝入一個箱子
?//找到第一個有足夠容量的箱子
int?child?=?2;??//從根的左孩子開始搜索
while?(child? {
int?winner?=?winTree.winner(child);
if?(bin[winner].unusedCapacity?jectSize[i])
child++;??????//第一個箱子在右子樹
child?*=?2;???????//移動到左孩子
}
int?binToUse;?????//設置為要使用的箱子
child?/=?2;?????//撤銷向最后的左孩子的移動
if?(child? {//在一個樹節點
binToUse?=?winTree.winner(child);
//若binToUse是右孩子,則要檢查箱子binToUse-1
//即使binToUse是左孩子,檢查箱子binToUse-1也不會有問題
if?(binToUse?>?1?&&?bin[binToUse?-?1].unusedCapacity?>=?objectSize[i])
binToUse--;
}
else??//當n是奇數
binToUse?=?winTree.winner(child?/?2);
number[i]?=?binToUse;
// cout?<“物品“?< bin[binToUse].unusedCapacity?-=?objectSize[i];
winTree.rePlay(binToUse);
}
select_sort(number?n);
cout?<“使用的箱子數:“?<}
void?bestFitPack(int?*objectSize?int?numberOfobjects?int?binCapacity)
{//輸出容量為binCapacity的最優箱子匹配.
?//objectSize[1:numberOfobjects]是物品大小
int?n?=?numberOfobjects;
int?*number?=?new?int[n?+?1];
int?binsUsed?=?0;
AVLTree*theTree?=?new?AVLTree();
AVLTreeNode*theBin=new?AVLTreeNode();
//將物品逐個裝箱
for?(int?i?=?1;?i?<=?n;?i++)
{//將物品i裝箱
?//尋找最匹配的箱子
AVLTreeNode?*bestBin?=?theTree->findGE(objectSize[i]);
if?(bestBin?==?NULL)
{//沒有足夠大的箱子,啟用一個新箱子
theBin->key?=?binCapacity;
theBin->n?=?++binsUsed;
}
else
{
//從樹theTree中刪除最匹配的箱子
*theBin?=?*bestBin;
???????theTree->remove(bestBin->key);
}
number[i]?=?theBin->n;
// cout?<“物品“?<n?<“個箱子中“< //將箱子插到樹中,除非箱子已滿
theBin->key?=?theBin->key?-?objectSize[i];
// cout?<“箱子“?<n?<“剩“?<key?<“空間“?< if?(theBin->key?>?0)
theTree->insert(theBin->keytheBin->n);
//theTree->print();
//cout?< //cout?< //cout?< }
select_sort(number?n);
cout?<“所用箱子數:“?<
}
/*void?best(int?*objectSize?int?numberOfOb
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????159892??2018-04-12?11:09??箱子裝箱問題\箱子裝箱問題.docx
?????文件??????12134??2017-05-20?15:54??箱子裝箱問題\代碼\AVLTree.h
?????文件????????559??2017-05-20?13:48??箱子裝箱問題\代碼\AVLTreeNode.h
?????文件????????595??2017-05-09?14:36??箱子裝箱問題\代碼\binaryTreeNode.h
?????文件????????180??2017-05-02?12:49??箱子裝箱問題\代碼\binType.h
?????文件???????3392??2017-05-02?15:29??箱子裝箱問題\代碼\completeWinnerTree.h
?????文件???????7403??2017-05-13?12:36??箱子裝箱問題\代碼\ConsoleApplication2.vcxproj
?????文件???????1645??2017-05-13?12:36??箱子裝箱問題\代碼\ConsoleApplication2.vcxproj.filters
?????文件???????3653??2017-05-13?10:25??箱子裝箱問題\代碼\dBinarySearchTreeWithGE.h
?????文件???????2643??2017-05-02?15:29??箱子裝箱問題\代碼\myExceptions.h
?????文件???????6105??2017-05-20?15:57??箱子裝箱問題\代碼\packing.cpp
?????文件???????2533??2017-05-02?15:20??箱子裝箱問題\代碼\packing.h
?????文件????????362??2017-05-08?20:59??箱子裝箱問題\代碼\pair.h
?????文件????????304??2017-05-20?15:57??箱子裝箱問題\代碼\Debug\ConsoleApplication2.log
?????文件?????232607??2017-05-20?15:57??箱子裝箱問題\代碼\Debug\packing.obj
?????文件?????879616??2017-05-20?15:57??箱子裝箱問題\代碼\Debug\vc141.idb
?????文件?????569344??2017-05-20?15:57??箱子裝箱問題\代碼\Debug\vc141.pdb
?????文件????????890??2017-05-20?15:57??箱子裝箱問題\代碼\Debug\ConsoleA.C0DA3C2C.tlog\CL.command.1.tlog
?????文件??????41886??2017-05-20?15:57??箱子裝箱問題\代碼\Debug\ConsoleA.C0DA3C2C.tlog\CL.read.1.tlog
?????文件????????872??2017-05-20?15:57??箱子裝箱問題\代碼\Debug\ConsoleA.C0DA3C2C.tlog\CL.write.1.tlog
?????文件????????247??2017-05-20?15:57??箱子裝箱問題\代碼\Debug\ConsoleA.C0DA3C2C.tlog\ConsoleApplication2.lastbuildstate
?????文件???????1560??2017-05-20?15:57??箱子裝箱問題\代碼\Debug\ConsoleA.C0DA3C2C.tlog\li
?????文件???????3462??2017-05-20?15:57??箱子裝箱問題\代碼\Debug\ConsoleA.C0DA3C2C.tlog\li
?????文件????????844??2017-05-20?15:57??箱子裝箱問題\代碼\Debug\ConsoleA.C0DA3C2C.tlog\li
?????目錄??????????0??2017-05-20?15:57??箱子裝箱問題\代碼\Debug\ConsoleA.C0DA3C2C.tlog
?????目錄??????????0??2017-05-20?15:57??箱子裝箱問題\代碼\Debug
?????目錄??????????0??2018-04-12?11:12??箱子裝箱問題\代碼
?????目錄??????????0??2017-05-20?15:57??箱子裝箱問題
-----------?---------??----------?-----??----
??????????????1932728????????????????????28
............此處省略1個文件信息
- 上一篇:FANUC roboguide破解軟件
- 下一篇:畢業生就業協議書樣本
評論
共有 條評論