Skip to content

Instantly share code, notes, and snippets.

@niklasfi
Created July 4, 2011 17:04
Show Gist options
  • Save niklasfi/1063621 to your computer and use it in GitHub Desktop.
Save niklasfi/1063621 to your computer and use it in GitHub Desktop.
#include "container.h"
unsigned int container::room_remaining() const{
return (unsigned int)(size - room_used);
}
#pragma once
#include <queue>
#include <vector>
struct object;
struct container{
unsigned int size;
unsigned int room_used;
unsigned int cycles_max;
unsigned int cycles_cur;
unsigned int freeze_time;
std::priority_queue<object> inside;
//std::priority_queue<object*,std::vector<object*>, std::greater<object>> outside;
unsigned int room_remaining() const;
container(){
}
};
#include "object.h"
/*
unsigned int initcycle, weight, value;
object::object(const container& parent, unsigned int weight, unsigned int value):
parent(&parent),initcycle(curcycle), weight(weight), value(value){};
*/
bool object::operator>(const object& o) const{
if(available() != o.available()) return available();
else if(value != o.value) return value > o.value;
else if(weight != o.weight) return weight < o.weight;
else return false;
}
bool object::operator<(const object& o) const{
return o > *this;
}
bool object::available() const{
return parent->cycles_cur - initcycle > parent->freeze_time;
}
bool object::fits() const{
return parent->room_remaining() >= weight;
}
#pragma once
struct container;
struct object{
public:
container* parent;
unsigned int initcycle;
unsigned int weight;
unsigned int value;
object(const container& parent, unsigned int weight, unsigned int value);
bool operator<(const object& o) const;
bool operator>(const object& o) const;
bool available() const;
bool fits() const;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment