version 1.15, 2005/02/17 08:01:32
|
version 1.16, 2005/02/17 09:40:09
|
|
|
| |
using namespace std; | using namespace std; |
| |
|
//Rizwan Kassim - rizwank@geekymedia.com (c) rizwan kassim 2005 |
|
//for use exculsively in the UCLA ACM 2005 Feb. Competition. |
|
|
//threading might be useful except for the fact that our target machine is likely to have a single processor | //threading might be useful except for the fact that our target machine is likely to have a single processor |
// what about task limiting from SEAS? | // what about task limiting from SEAS? |
// actually sparc machines on ugrad are multiple processor -- could I thread/fork the calculations? would overhead > savings | // actually sparc machines on ugrad are multiple processor -- could I thread/fork the calculations? would overhead > savings |
|
|
// * Creates an item and places it into the priority queue * | // * Creates an item and places it into the priority queue * |
// ****************************************************************** | // ****************************************************************** |
void backpack::putItem(ITEM_MASS weight){ //, ITEM_MASS cost){ | void backpack::putItem(ITEM_MASS weight){ //, ITEM_MASS cost){ |
item temp_item; |
item temp_item;// printf("%d, %d, %d, %d, %d\n",item_array[0],item_array[1],item_array[2],item_array[3],item_array[4]); |
|
|
temp_item.setData(weight);//,cost);//,(int)(this->item_queue.size())+1); // sometimes this starts at 2000? | temp_item.setData(weight);//,cost);//,(int)(this->item_queue.size())+1); // sometimes this starts at 2000? |
this->item_queue.push(temp_item); | this->item_queue.push(temp_item); |
} | } |
|
|
this->item_array[i] = this->item_queue.top(); | this->item_array[i] = this->item_queue.top(); |
this->item_queue.pop(); | this->item_queue.pop(); |
} | } |
|
// printf("%d, %d, %d, %d, %d\n",item_array[0].getWeight(),item_array[1].getWeight(),item_array[2].getWeight(),item_array[3].getWeight(),item_array[4].getWeight()); |
|
|
} | } |
| |
// ****************************************************************** | // ****************************************************************** |
|
|
onwards = 0; | onwards = 0; |
} | } |
else { | else { |
// this->worknodeCount++; |
this->worknodeCount++; |
temp_key.flagNext(); | temp_key.flagNext(); |
this->key_queue.push(temp_key); | this->key_queue.push(temp_key); |
// this->addnodeCount++; |
this->addnodeCount++; |
| |
// try this --- compare quicksorted before and after because of greedy grabbing largest | // try this --- compare quicksorted before and after because of greedy grabbing largest |
//should find other comparator for weight with sub data like ... pct done | //should find other comparator for weight with sub data like ... pct done |
|
|
temp_key.addCurItem(); | temp_key.addCurItem(); |
if (temp_key.getBound() != 0){ //insert only if active. | if (temp_key.getBound() != 0){ //insert only if active. |
this->key_queue.push(temp_key); | this->key_queue.push(temp_key); |
// this->addnodeCount++; |
this->addnodeCount++; |
} | } |
} | } |
// commenting out worknode trackerincreases speed by 3% | // commenting out worknode trackerincreases speed by 3% |
|
|
// filter out oversizes BEFORE we insert them above, therefore making life complicated | // filter out oversizes BEFORE we insert them above, therefore making life complicated |
| |
vector<ITEM_MASS>::iterator itInventory; | vector<ITEM_MASS>::iterator itInventory; |
|
double sum_test = 0; |
| |
// printf("inventory before %d\n",inventory.size()); | // printf("inventory before %d\n",inventory.size()); |
for(itInventory = inventory.begin(); itInventory != inventory.end(); itInventory++) { | for(itInventory = inventory.begin(); itInventory != inventory.end(); itInventory++) { |
|
|
// printf("%d removed at %d, left!\n",*itInventory,inventory.size()); | // printf("%d removed at %d, left!\n",*itInventory,inventory.size()); |
// remove elements that are too large. its a n increase here, but >>n increase if done later | // remove elements that are too large. its a n increase here, but >>n increase if done later |
} | } |
|
sum_test = sum_test + *itInventory; |
} | } |
|
if (( sum_test < palette_size) || (inventory.size()==0)) { |
|
printf("CANNOT FILL PALLET\n"); return 5;} |
|
// either all the elements combined would not make a complete crate |
|
// or all the elements are too big. |
| |
backpack knapsackOne; | backpack knapsackOne; |
| |