== 느낀점 및 설명 == 뭔가 재미있어 보여서 만들기 시작했다. C++이라서 그런지.. 내가그런건지는 몰라도 이상하게 클래스로만 자면 C로 작성하는 것 보다 시간이 더 걸리는듯.. 하지만 재미있다!!^^* 재미삼아 뚝딱 거리다 보니.. 이미 버스 사람 정거장 길... 질러버렸.. 그렇지만 아직까지 일은 하고있고, 시간도 없고, 해서 좀 낭비스럽지만 메모리 관리 및 소스가 엉망진창이다.ㅎ 헤헤헤.. 그래도 재미있으니 뭐..ㅎㅎ (사실 이 증명 시뮬레이션은 편도에서 버스 용량이 무한대고 설사 승객이 내리지 않더라도 승객이 타고, 타는데 시간이 걸린다는 것만으로도 버스가 몰려다니는 것으로 증명되어 있으나.. 재미없자넝~ 버스는 자고로 용량이 있어야.. 그리고탔으면 내리는게 인지상정.ㅎ) 음 노약자석이라던가.. 길과 길을 이어버린다거나.. 버스를 왕복시킨다거나.. 하는것은 해보고 싶지만, 시간상 보류! 사실 출력부분이 대부분 테스트용으로 만들어 진건데.. 일단 임시로 그대로 사용하기로 했다. 나중에 휴가기간에 소스좀 수정하도록 하겠다. 들떠서 다 적고나서 소스의 설명이 안되있는것을 깨닫고 시급히 수정.. 그런데 어느분이 그사이 페이지를 변경하셔서 눈물을 머금고 다시작성한다.ㅠ.ㅜ ---- 버스는 동일 간격으로 생성되게 되어있으며, 승객은 랜덤으로 생성된다.( 승객이 생성되는 비율을 역을 만들때 정할 수 있다. ) 편도인 관계로 승객의 목적지는 승객이 생성된 이후의 역중 한곳(랜덤)으로 정해진다. 또한 이런 문제로 마지막 역은 승객을 만들(!)수 없다. 버스가 자신의 속도(만들때 정할 수 있으며 이 소스에는 80으로 통일하였다.)로 움직이는데 한턴이 소모된다. (앞에 차량이 있어서 정차하거나, 역에 들어가게되어 자신의 이동거리를 다 가지 못하더라도 동일하게 한턴이 소모된다.) 승객 1인을 태우고, 승객1인을 내리는데 1턴이 소모된다. (둘중에 한가지 과정만이 이루어 지더라도 동일하게 1턴이 소모된다.) 이러한 규칙을 기본으로 해서 시뮬레이션 하고 있다. ---- (수정당해서 날렸던 충격이 큰터라 많이 설명이 줄었지만 이해하리라 믿는다.^^) - 물런 재미가 없긴 하겠지만 이 증명은 버스가 편도로 움직이고 버스용량이 무한이며, 승객이 내리지 않더라도 승객이 타고 승객이 타는데 시간만 걸린다면 버스의 몰림현상이 발생한다. (고로 증명하기 위해 소스를 많이 짤 필요가 없을 수도 있다. 재미가 없겠지만..ㅎ) ---- 메모리 낭비를 요로코롬 줄였답니다.^^* 많이 줄인대신에 연산이 좀 늘어난 듯 하지만.. 원체 원본이 메모리 낭비의 회심작..;;; 이다 보니..ㅎ 아아 메모리 관리는 너무 힘들엇..ㅠ.ㅜ 저번 소스에서 발견되지 않았던 문제점이 있어 그것 역시 수정하였습니다. 잘못된 메모리 접근오류..ㅠ.ㅜ 넘 찾기 힘들다는.ㅎ == 소스 == === main.cpp === {{{~cpp #include "bus_and_man.h" #include using namespace std; void Set_memory(); void Call_act(); road *cau_road; void main() { cout << "시스템을 초기화 합니다.\n"; Set_memory(); Call_act(); } void Set_memory() { cau_road=new road(3000); cau_road->Build("정문",5,0,5); cau_road->Build("issac",10,700,5); cau_road->Build("시장",3,1000,5); cau_road->Build("중문",10,1320,5); cau_road->Build("곰두리",10,1700,5); cau_road->Build("공대건물",2,2100,5); cau_road->Build("주차장",30,2750,5); cau_road->Build("후문",10,2999,5); } void Call_act() { for (register int i=1; i<20; ++i) { for (register int j=0; j<5; ++j) { cau_road->Act(); cout << "\n"; system("PAUSE"); cout << "\n"; } cau_road->Start_car(i,20,0,80); } delete cau_road; } }}} === bus_and_man.cpp === {{{~cpp //버스 위치. //승객 //하는 일 #include #include #include #include "bus_and_man.h" using namespace std; const int MOVE=1; const int STOP=0; man::man(int input_from, int input_to) { from=input_from; to=input_to; } man::~man() { } int man::where_go() { return to; } station::station(int input_station_number, char *input_name, int input_percent, int input_size ) { strcpy(name,input_name); percent=input_percent; station_size=input_size; number_man=0; station_number=input_station_number; humans=new man*[station_size]; for (register int i=0; icar_move(&in_station, speed, where); if (1==in_station) state=STOP; if (-1==temp_where) in_road->car_stop(where); else { where=temp_where; cout << number << "번 버스가 " << where << "로 이동하였습니다.\n"; } } void bus::stop(station *in_station, road* in_road) { man*in_people=in_station->out_people(); if (0!=in_people) { humans[number_man]=in_people; ++number_man; cout << number << "번 버스가 승객을 승차하였습니다.\n"; } int suched=0; for (register int i=0; iwhere_here()==humans[i]->where_go()) { delete humans[i]; humans[i]=0; for (register int j=i+1; j=0; --i) { if (0!=buildings[i]) buildings[i]->act(number_station); if (0!=cars[i]) cars[i]->act(buildings[i],this); } } int road::car_move(int *state, int speed, int where) { register int i; for (i=where+1; i<=where+speed; ++i) { if (i>=road_long) return -1; if (0!=cars[i]) break; if (0!=buildings[i]) { *state=1; ++i; break; } } if (i-1!=where) { cars[i-1]=cars[where]; cars[where]=0; } return i-1; } void road::car_stop(int where) { delete cars[where]; cars[where]=0; } }}} === bus_and_man.h === {{{~cpp class man; class station; class bus; class road; class man{ private: int from; int to; public: man(int input_from, int input_to); ~man(); int where_go(); }; class station{ private: char name[256]; int station_number; int percent; int station_size; int number_man; man **humans; void make_people(int); public: station(int, char*, int, int); ~station(); man* out_people(); int where_here(); void act(int); }; class bus{ private: int number; int bus_size; int state; int where; man **humans; int number_man; int speed; void move(road*); void stop(station*, road*); public: bus(int , int , int , int ); ~bus(); void act(station* , road* ); }; class road{ private: int road_long; int number_station; bus **cars; station **buildings; public: road (int ); ~road(); int Build(char*, int , int, int ); int Start_car(int , int , int , int ); void Act(); int car_move(int*, int , int ); void car_stop(int); }; }}} == 1차 수정버전 소스 == === main.cpp === {{{~cpp #include "bus_and_man.h" #include using namespace std; void Set_memory(); void Call_act(); road *cau_road; void main() { cout << "시스템을 초기화 합니다.\n"; Set_memory(); Call_act(); } void Set_memory() { cau_road=new road(3000); cau_road->Build("정문",5,0,5); cau_road->Build("issac",10,700,5); cau_road->Build("시장",3,1000,5); cau_road->Build("중문",10,1320,5); cau_road->Build("곰두리",10,1700,5); cau_road->Build("공대건물",2,2100,5); cau_road->Build("주차장",30,2750,5); cau_road->Build("후문",10,2999,5); } void Call_act() { for (register int i=1; i<20; ++i) { for (register int j=0; j<5; ++j) { cau_road->Act(); cout << "\n"; system("PAUSE"); cout << "\n"; } cau_road->Start_car(i,20,0,80); } delete cau_road; } }}} === bus_and_man.cpp === {{{~cpp //버스 위치. //승객 //하는 일 #include #include #include #include "bus_and_man.h" using namespace std; const int MOVE=1; const int STOP=0; man::man(int input_from, int input_to) { from=input_from; to=input_to; } man::~man() { } int man::where_go() { return to; } station::station(int input_station_number, char *input_name, int input_percent, int input_size, int input_where) { strcpy(name,input_name); percent=input_percent; station_size=input_size; number_man=0; station_number=input_station_number; where=input_where; humans=new man*[station_size]; for (register int i=0; icar_move(&in_station, speed, where); if (1==in_station) state=STOP; if (-1==temp_where) in_road->car_stop(number); else { where=temp_where; cout << number << "번 버스가 " << where << "로 이동하였습니다.\n"; } } void bus::stop(station *in_station, road* in_road) { man*in_people=0; if (number_manout_people(); if (0!=in_people) { humans[number_man]=in_people; ++number_man; cout << number << "번 버스가 승객을 승차하였습니다.\n"; } } int suched=0; for (register int i=0; iwhere_here()==humans[i]->where_go()) { delete humans[i]; humans[i]=0; for (register int j=i+1; jwhere_am_i()==where) { cout << "역을 생성하는데 실패하였습니다.\n"; return -1; } } station** temp=new station*[number_station+1]; for (register int i=0; iwhere_am_i()==input_where) { cout << "차를 생성하는데 실패하였습니다.\n"; return -1; } } bus** temp=new bus*[number_bus+1]; for (register int i=0; iact(number_station); for (register int i=0; iwhere_am_i()==cars[i]->where_am_i()) { cars[i]->act(buildings[j],this); break; } } if (j==number_station) cars[i]->act(0,this); } } int road::car_move(int *state, int speed, int where) { int temp_where=where+speed; for (register int i=0; iwhere_am_i() && temp_where>=buildings[i]->where_am_i()) { temp_where=buildings[i]->where_am_i(); *state=1; } } for (register int i=0; iwhere_am_i() && temp_where>=cars[i]->where_am_i()) { temp_where=cars[i]->where_am_i(); *state=0; } } if (temp_where>=road_long) return -1; if (*state==0) return temp_where-1; else return temp_where; } void road::car_stop(int number) { bus** temp=new bus*[number_bus-1]; int swit=0; for (register int i=0; iwhat_number()==number) { delete cars[i]; swit=1; } else temp[i]=cars[i]; } else temp[i-1]=cars[i]; } delete cars; cars=temp; --number_bus; } }}} === bus_and_man.h === {{{~cpp class man; class station; class bus; class road; class man{ private: int from; int to; public: man(int input_from, int input_to); ~man(); int where_go(); }; class station{ private: char name[256]; int station_number; int percent; int station_size; int number_man; int where; man **humans; void make_people(int); public: station(int, char*, int, int, int); ~station(); man* out_people(); int where_here(); void act(int); int where_am_i(); }; class bus{ private: int number; int bus_size; int state; int where; man **humans; int number_man; int speed; void move(road*); void stop(station*, road*); public: bus(int , int , int , int ); ~bus(); void act(station* , road* ); int where_am_i(); int what_number(); }; class road{ private: int road_long; int number_station; int number_bus; bus **cars; station **buildings; public: road (int ); ~road(); int Build(char*, int , int, int ); int Start_car( int, int , int , int ); void Act(); int car_move(int*, int , int ); void car_stop(int); }; }}} == 나에게 할말 == * 오~ 현태도 짜버렸구나 ㅋㅋ - [상협] └헤헤헤.ㅎㅎ 재밌어 보여서..ㅎ 근데 소스가 엉망이에요.ㅎ 빨리 일을 끝내야징.. 쉬는 시간이 없어서.ㅎ 하루=잠+일; 이라는..ㅠ.ㅜ 일 끝나면 소스 수정할께요.^^* -[조현태] ---- [BusSimulation]