using namespace std;
void remove(int list[], int listLength, int removeItem);
struct Vehicle {
int id;
int priority;
int resource_utilization;
};
class CompareVehicle {
public://this creates two vehicle objects and compares their properties and sets their places in the queue
bool operator() (Vehicle& v1, Vehicle& v2) {
if(v1.priority < v2.priority) return true;
return false;
}
};
//global variables
int num1[20], num2[20], num3[20], num11[20], num21[20], num31[20];
//for now numbers will be fixed
priority_queue<Vehicle, vector<Vehicle>, CompareVehicle> pq;
//array of car objects with first value being process id second is priority and third being resource_utilization
// Vehicle c [3] = {{56, 1, 2}, {19, 9, 45}};
//car lot array of vehicle type to hold cars by priority
Vehicle temp[10] = {};
int lot[10] = {};
unsigned int i;
list<unsigned int> my_lot;
list<unsigned int>::iterator it1,it2;
//temp counter
int t=0;
int idk = 0;
int free_space = 0;
int length = 10;
//end of global variables
void gen_rand() {
cout<<"All vehicles that came in"<<endl;
for(int i=0; i<10; ++i) {
num1[i] = rand() % 1000 + 1;//generate a random process ID 1 - 1000
num2[i] = rand() % 10 + 1;//generate a random priority 1 - 10
num3[i] = rand() % 6000 + 10000;//generate a random resource_utilzation amount 1 - 30
cout<<num1[i]<<setw(3)<<" "<<num2[i]<<setw(3)<<" "<<num3[i]<<endl;
}//end for
}//end gen_rand
void gen_again() {
idk = rand() % 4 + 1;
for(int i = 0; i<idk; i++) {
num1[i] = rand() % 1000 + 1;//generate a random process ID 1 - 1000
num2[i] = rand() % 10 + 1;//generate a random priority 1 - 10
num3[i] = rand() % 6000 + 10000;//generate a random resource_utilzation amount 1 - 30
cout<<num1[i]<<setw(3)<<" "<<num2[i]<<setw(3)<<" "<<num3[i]<<endl;
}//end for
//view_lot();
//----------------------------------------
// cout<<pq.size()<<endl;//last car in lot was not removed
//cout<<"new cars waiting "<<endl;
}
void decision() {
int count=0;
int what_to_do = gen_decide();
if(what_to_do == 1) {//add car
gen_again();
requeue();
while(!pq.empty()) {
Vehicle v2 = pq.top();
cout<<"Vehicle "<<v2.id<<" has a priority of " <<v2.priority<<" and will now enter the car park"<<endl<<endl;
my_lot.push_back(v2.id);
//it1 = it2 = my_lot.begin();
pq.pop();//take vehicle off list
decision();
}//end while
}//end if
else {//remove cars from list
int remove_item = rand() % 10 + 1;
advance(it1, remove_item);
it1 = my_lot.erase(it1);
cout<<"vehicle on lot "<<remove_item<<" has finished"<<endl;
cout << endl;
for(it1 = my_lot.begin(); it1!=my_lot.end(); ++it1){
count++;
cout<<"Cars on lot now are "<<*it1<<" on "<<count<<endl;
}//end for
decision();
}//end else
}//end decision function
void run_after() {
while(!pq.empty()) {//needs more logic
Vehicle v2 = pq.top();
cout<<"Vehicle "<<v2.id<<" has a priority of " <<v2.priority<<" and will now enter the car park"<<endl<<endl;
//lot[t] = v2.id; //copy vehicle to lot then pop it off main list
my_lot.push_back(v2.id);
//it1 = it2 = my_lot.begin();
pq.pop();//take vehicle off list
t++;
//cout << "That size exceeds the limit.\n";
decision();
//break;