-
Notifications
You must be signed in to change notification settings - Fork 0
/
vehicle.cpp
67 lines (51 loc) · 2.78 KB
/
vehicle.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// Created by cyx02 on 2022/6/27.
//
#include "vehicle.h"
#include "math.h"
#include <cstdio>
#include <stddef.h>
#include <iostream>
using namespace std;
double distance_between_vehicle(const struct vehicle* aCar, const struct vehicle* bCar){
return sqrt((aCar->x - bCar->x)*(aCar->x - bCar->x) + (aCar->y - bCar->y)*(aCar->y - bCar->y));
}
void printVehilces(struct Duallist *ALL_Vehicles){
struct Item *aItem;
struct vehicle* aCar;
aItem =ALL_Vehicles-> head;
while(aItem != NULL){
aCar = (struct vehicle*)aItem->datap;
cout<<"handled="<<aCar->handled<<" ,id="<<aCar->id<<" ,x="<<aCar->x <<" ,y="<<aCar->y <<" ,CommRange="<<aCar->commRadius <<" ,slot_occupied="<< aCar->slot_occupied <<" ,slot_condition="<<aCar->slot_condition<<" ,pos="<<aCar->pos<<", speed="<<aCar->speed<<", decel="<<aCar->acc<<", resource_pool="<<aCar->resource_pool<<", angle="<<aCar->angle<<endl;
aItem = aItem->next;
// (aCar->queue_Vehicles)[aCar]++;
//(aCar->queue_Vehicles).clear();
}
}
void logVehilcesInfo(struct Duallist *ALL_Vehicles, ofstream & logfile){
struct Item *aItem;
struct vehicle* aCar;
aItem =ALL_Vehicles-> head;
while(aItem != NULL){
aCar = (struct vehicle*)aItem->datap;
logfile<<"handled="<<aCar->handled<<" ,id="<<aCar->id<<", lane="<<aCar->lane<<" ,x="<<aCar->x <<" ,y="<<aCar->y <<" ,CommRange="<<aCar->commRadius <<" ,slot_occupied="<< aCar->slot_occupied <<" ,slot_condition="<<aCar->slot_condition<<" ,pos="<<aCar->pos<<", speed="<<aCar->speed<<", decel="<<aCar->acc<<", slot_resource="<<aCar->resource_pool<<", angle="<<aCar->angle<<", Role_condition="<<aCar->role_condition<<", slot_appeared="<<aCar->slot_appeared<<endl;
aItem = aItem->next;
// (aCar->queue_Vehicles)[aCar]++;
//(aCar->queue_Vehicles).clear();
}
}
void logACar(struct vehicle* aCar){
log_process_file << "id=" <<aCar->id<<", x="<<aCar->x<<", y="<<aCar->y<<", CommR="<<aCar->commRadius<<", Slot_Occupied="<<aCar->slot_occupied<<", Role_condition="<<aCar->role_condition<<", slot_appeared:"<<aCar->slot_appeared<<endl;
log_process_file << " counter_tx="<<aCar->counter_tx<<", counter_rx_TxCollision="<<aCar->counter_rx_TxCollision<<", counter_rx_RxCollision="<<aCar->counter_rx_RxCollision<<", counter_rx_normal="<<aCar->counter_rx_normal<<endl;
log_process_file <<" OHN:"<<endl;
for(int i = 0; i <SlotPerFrame; i++)
if(aCar->OHN[i] != nullptr)
log_process_file<<i<<" : "<<aCar->OHN[i]->id<<" ";
log_process_file<<endl;
log_process_file <<" THN:"<<endl;
for(int i = 0; i < SlotPerFrame; i++)
if(aCar->THN[i] != nullptr)
log_process_file<<i<<" : "<<aCar->THN[i]->id<<" ";
log_process_file<<endl;
//logfile<<" Neighbors in CommRange"<<endl;
}