LAMPIRAN A
// BUSWAYView.cpp : implementation of the CBUSWAYView class //
#include "stdafx.h" #include "BUSWAY.h"
#include "BUSWAYSet.h" #include "BUSWAYDoc.h" #include "BUSWAYView.h"
#include "LibDraw.h" #include "Algorithm.h" #include "BUSWAYThread.h"
#ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif
#define INFINITY
1000000000
int TPrice[2] = {2000,3500};
//typedef unsigned int uint; using namespace std; ///////////////////////////////////////////////////////////////////////////// // CBUSWAYView
IMPLEMENT_DYNCREATE(CBUSWAYView, CRecordView)
BEGIN_MESSAGE_MAP(CBUSWAYView, CRecordView) //{{AFX_MSG_MAP(CBUSWAYView) ON_BN_CLICKED(IDC_BTN_GREEDY, OnBtnGreedy) ON_BN_CLICKED(IDC_BTN_CLEAR, OnBtnClear) ON_BN_CLICKED(IDC_BTN_ADJ, OnBtnAdj) ON_BN_CLICKED(IDC_BTN_DIST, OnBtnDist) ON_BN_CLICKED(IDC_BTN_TRANSHAL, OnBtnTranshal) ON_WM_TIMER() //}}AFX_MSG_MAP END_MESSAGE_MAP()
///////////////////////////////////////////////////////////////////////////// // CBUSWAYView construction/destruction
CBUSWAYView::CBUSWAYView() : CRecordView(CBUSWAYView::IDD) { //{{AFX_DATA_INIT(CBUSWAYView) m_pSet = NULL; m_HKorDstOut = _T(""); m_HKorSrcOut = _T(""); m_HNodeDstOut = _T(""); m_HNodeSrcOut = _T(""); m_HNameDstOut = _T(""); m_HNameSrcOut = _T(""); m_TotalCost = _T(""); m_Info = _T(""); m_Path12 = _T(""); m_Path14 = _T(""); m_Path23 = _T(""); m_Path24 = _T("");
m_Path25 = _T(""); m_Path45 = _T(""); m_Path46 = _T(""); m_Path57 = _T(""); m_HNameDstIn = _T(""); m_HNameSrcIn = _T(""); m_PictureInfo = _T(""); m_MatrixOut = _T(""); m_MatrixOutName = _T(""); m_MatrixOutLabel = _T(""); m_GeneralFac = _T(""); m_StSysTime = _T(""); m_pBuswayThread = NULL; m_InfoPrice = _T(""); //}}AFX_DATA_INIT // TODO: add construction code here }
CBUSWAYView::~CBUSWAYView() { }
void CBUSWAYView::DoDataExchange(CDataExchange* pDX) { CRecordView::DoDataExchange(pDX); //{{AFX_DATA_MAP(CBUSWAYView) DDX_Control(pDX, IDC_EDT_TIME, m_EdtSysTime); DDX_Control(pDX, IDC_FRAME_KORIDOR, m_FrameKoridor); DDX_Text(pDX, IDC_STAT_HKDST_OUT, m_HKorDstOut); DDX_Text(pDX, IDC_STAT_HKSRC_OUT, m_HKorSrcOut); DDX_Text(pDX, IDC_STAT_HNDDST_OUT, m_HNodeDstOut);
DDX_Text(pDX, IDC_STAT_HNDSRC_OUT, m_HNodeSrcOut); DDX_Text(pDX, IDC_STAT_HNDST_OUT, m_HNameDstOut); DDX_Text(pDX, IDC_STAT_HNSRC_OUT, m_HNameSrcOut); DDX_Text(pDX, IDC_STAT_TOTAL_COST, m_TotalCost); DDX_Text(pDX, IDC_STAT_INFO, m_Info); DDX_Text(pDX, IDC_STAT_P12, m_Path12); DDX_Text(pDX, IDC_STAT_P14, m_Path14); DDX_Text(pDX, IDC_STAT_P23, m_Path23); DDX_Text(pDX, IDC_STAT_P24, m_Path24); DDX_Text(pDX, IDC_STAT_P25, m_Path25); DDX_Text(pDX, IDC_STAT_P45, m_Path45); DDX_Text(pDX, IDC_STAT_P46, m_Path46); DDX_Text(pDX, IDC_STAT_P57, m_Path57); DDX_CBString(pDX, IDC_COMBO_HNDST_IN, m_HNameDstIn); DDX_CBString(pDX, IDC_COMBO_HNSRC_IN, m_HNameSrcIn); DDX_Text(pDX, IDC_STAT_INFO_PIC, m_PictureInfo); DDX_Text(pDX, IDC_STAT_MADJ, m_MatrixOut); DDX_Text(pDX, IDC_STAT_MATRIX_NAME, m_MatrixOutName); DDX_Text(pDX, IDC_STAT_MATRICES, m_MatrixOutLabel); DDX_Text(pDX, IDC_STAT_GENERAL, m_GeneralFac); DDX_FieldText(pDX, IDC_EDT_SIM_HID, m_pSet->m_ID, m_pSet); DDX_FieldText(pDX, IDC_EDT_SIM_HNAME, m_pSet->m_halte_name, m_pSet); DDX_FieldText(pDX, IDC_EDT_SIM_KORIDOR, m_pSet->m_koridor, m_pSet); DDX_FieldText(pDX, IDC_EDT_SIM_NODE, m_pSet->m_node_num, m_pSet); DDX_Text(pDX, IDC_STAT_PRICE, m_InfoPrice); //}}AFX_DATA_MAP }
BOOL CBUSWAYView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CRecordView::PreCreateWindow(cs); }
void CBUSWAYView::OnInitialUpdate() { m_pSet = &GetDocument()->m_bUSWAYSet; CRecordView::OnInitialUpdate(); GetParentFrame()->RecalcLayout(); ResizeParentToFit();
m_pDC = m_FrameKoridor.GetWindowDC(); Init(); CreateKoridorNodeArray(); CreateKoridorMatrix(); CreateGreedyNodeArray(); InitLookUpTblDist(); CalcHTransDistance();
PrintNullMatrix();
m_pBuswayThread = new CBUSWAYThread; SetTimer(1,1000,NULL); }
///////////////////////////////////////////////////////////////////////////// // CBUSWAYView diagnostics
#ifdef _DEBUG void CBUSWAYView::AssertValid() const
{ CRecordView::AssertValid(); }
void CBUSWAYView::Dump(CDumpContext& dc) const { CRecordView::Dump(dc); }
CBUSWAYDoc* CBUSWAYView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CBUSWAYDoc))); return (CBUSWAYDoc*)m_pDocument; } #endif //_DEBUG
///////////////////////////////////////////////////////////////////////////// // CBUSWAYView database support CRecordset* CBUSWAYView::OnGetRecordset() { return m_pSet; }
void CBUSWAYView::OnTimer(UINT nIDEvent) { if(nIDEvent == 1) { if(m_pBuswayThread != NULL) { CString sTime = ""; m_pBuswayThread->GetSysTime(sTime);
m_EdtSysTime.SetSel(0,-1); m_EdtSysTime.Clear(); m_EdtSysTime.ReplaceSel(sTime); m_EdtSysTime.UpdateData(false); } } CRecordView::OnTimer(nIDEvent); } ///////////////////////////////////////////////////////////////////////////// // CBUSWAYView message handlers
void CBUSWAYView::OnBtnGreedy() { // TODO: Add your control notification handler code here //int i, j; int error = 3; UpdateData(TRUE);
ResetLabel(); ResetGreedyPath(); ResetCost(); ResetCloseHalte(); OnDraw(m_pDC);
// validasi masukan nama halte asal & halte tujuan
if((GetFilterStatus("halte_name", m_HNameSrcIn) == -1) && (GetFilterStatus("halte_name", m_HNameDstIn) == -1)) { error = 3; ReFilterDB();
// masukan halte asal & tujuan
} else if(GetFilterStatus("halte_name", m_HNameDstIn) == -1) // masukan halte tujuan { error = 2; ReFilterDB(); } else if(GetFilterStatus("halte_name", m_HNameSrcIn) == -1) // masukan halte asal { error = 1; ReFilterDB(); } else { error = 0; ReFilterDB(); }
m_Info = ""; switch(error) { case 0: { int i, j, calculate; if(ValidasiName() == -1) { ProcessInfo(); }
// Cost Information calculate = CalcDistance(); //m_TotalCost.Format("%d", j);
if(m_HKorSrcOut == m_HKorDstOut) { i = atoi(m_HKorDstOut);
i = i == 6 ? i+1 : (i == 7 ? i-1 : i);
m_Info = "Perjalanan akan berlangsung pada Koridor yang Sama"; m_NodeArray[i].SetAsSource(m_pDC); } else { // Solution with greedy algorithm using djikstra metode i = atoi(m_HKorSrcOut); j = atoi(m_HKorDstOut); i = i == 6 ? i+1 : (i == 7 ? i-1 : i); j = j == 6 ? j+1 : (j == 7 ? j-1 : j);
m_NodeArray[i].SetAsSource(m_pDC); m_NodeArray[j].SetAsDestination(m_pDC);
} PrintTicketPrice(atoi(m_HKorSrcOut)); break; } case 1: { MessageBox("Record Halte Asal tidak ditemukan!"); break; } case 2: {
MessageBox("Record Halte Tujuan tidak ditemukan!"); break; } case 3: { MessageBox("Record Halte Asal & Tujuan tidak ditemukan!"); break; } default: MessageBox("Internal Error!"); break; }
ReFilterDB();
UpdateData(false); }
void CBUSWAYView::OnBtnClear() { // TODO: Add your control notification handler code here OnDraw(m_pDC); Init(); PrintNullMatrix(); }
void CBUSWAYView::Init() { m_HNameDstIn = _T(""); m_HNameSrcIn = _T(""); m_HKorDstOut = "-";
m_HKorSrcOut = "-"; m_HNodeDstOut = "-"; m_HNodeSrcOut = "-"; m_HNameDstOut = "-"; m_HNameSrcOut = "-"; m_Path12 = "-"; m_Path14 = "-"; m_Path23 = "-"; m_Path24 = "-"; m_Path25 = "-"; m_Path45 = "-"; m_Path46 = "-"; m_Path57 = "-"; m_TotalCost = "-"; m_Info = "Silahkan Memasukkan Halte Asal dan Tujuan Anda"; m_GeneralFac = "-"; m_InfoPrice = "-"; PrintPictureInfo();
UpdateData(false); }
int CBUSWAYView::GetFilterStatus(CString sFilterRec, CString sRec) { int retVal = -1; int recCount; CString sFilter;
sFilter = sFilterRec + " = '" + sRec + "'";
m_pSet->Close(); m_pSet->m_strFilter = sFilter; m_pSet->Open(); recCount = m_pSet->GetRecordCount();
if(recCount == 0) { return retVal; } return (retVal = 0); }
void CBUSWAYView::OnDraw(CDC* pDC) { // TODO: Add your specialized code here and/or call the base class m_pDC = m_FrameKoridor.GetWindowDC();
RECT rect; int nCircle;
GetWindowRect(&rect);
m_NodeArray.SetSize(1,-1); m_PathArray.SetSize(1,-1); for(nCircle=0; nCircle<7; nCircle++) { unsigned int x = 30 + (nCircle%3* 80); unsigned int y = 30 + (nCircle/3* 100); unsigned int r = 10;
CMFCCircle newCircle(x,y,r);
m_NodeArray.Add(newCircle); newCircle.SetBorderWidth(3); newCircle.SetBorderColor(RGB(255,255,255)); newCircle.SetBorder(true); newCircle.SetFillColor(RGB(0,0,0)); newCircle.SetFill(true); newCircle.Draw(m_pDC); }
m_NodeArray[1].SetPathTo(m_NodeArray[2].GetX(),m_NodeArray[2].GetY(), m_pDC); m_NodeArray[1].SetPathTo(m_NodeArray[4].GetX(),m_NodeArray[4].GetY(), m_pDC); m_NodeArray[2].SetPathTo(m_NodeArray[3].GetX(),m_NodeArray[3].GetY(), m_pDC); m_NodeArray[2].SetPathTo(m_NodeArray[4].GetX(),m_NodeArray[4].GetY(), m_pDC); m_NodeArray[2].SetPathTo(m_NodeArray[5].GetX(),m_NodeArray[5].GetY(), m_pDC); m_NodeArray[4].SetPathTo(m_NodeArray[5].GetX(),m_NodeArray[5].GetY(), m_pDC); m_NodeArray[4].SetPathTo(m_NodeArray[7].GetX(),m_NodeArray[7].GetY(), m_pDC); m_NodeArray[5].SetPathTo(m_NodeArray[6].GetX(),m_NodeArray[6].GetY(), m_pDC);
}
void CBUSWAYView::ReFilterDB() { m_pSet->Close(); m_pSet->m_strFilter = ""; m_pSet->Open(); }
void CBUSWAYView::ProcessInfo() { // Source Information GetFilterStatus("halte_name", m_HNameSrcIn);
m_HNameSrcOut.Format("%s",m_pSet->m_halte_name); m_HKorSrcOut.Format("%d",m_pSet->m_koridor); m_HNodeSrcOut.Format("%d",m_pSet->m_node_num);
// Destination Information GetFilterStatus("halte_name", m_HNameDstIn);
m_HNameDstOut.Format("%s",m_pSet->m_halte_name); m_HKorDstOut.Format("%d",m_pSet->m_koridor); m_HNodeDstOut.Format("%d",m_pSet->m_node_num); }
int CBUSWAYView::ValidasiName() { int retVal = -1; int nodeDstNum, nodeSrcNum, i,j, k; int korDstNum = -1;
// destination and source can be in one corridor, so.. for(i=0; i
m_HKorDstOut.Format("%d", korDstNum);
m_HNameDstOut = m_HNameDstIn; m_HNameDstOut.Format("%s", m_HNameDstIn);
nodeDstNum = GetHalteNode(korDstNum, m_HNameDstIn); m_HNodeDstOut.Format("%d",nodeDstNum);
for(k=0; k<m_HalteArray[korDstNum].GetSize(); k++) { if(!strcmp(m_HNameSrcIn, m_HalteArray[korDstNum][k].GetHalteName())) { m_HNameSrcOut.Format("%s",m_HNameSrcIn); //Source halte name m_HKorSrcOut.Format("%d", korDstNum); //Source koridor number nodeSrcNum = GetHalteNode(korDstNum, m_HNameSrcIn); m_HNodeSrcOut.Format("%d", nodeSrcNum); //Source node number return 0; } } } } } return retVal; }
void CBUSWAYView::CreateKoridorNodeArray() { int i; for(i=1; i<=8; i++) { m_HalteArray[i].SetSize(1,-1); CreateNodeMatrix(i, m_HalteArray[i]); }
CString a = m_HalteArray[7][13].GetHalteName(); }
void CBUSWAYView::CreateGreedyNodeArray() { int i; m_HalteGrdArray.SetSize(1,-1);
for(i=1; i<=NUM_TRANSHAL; i++) { CHalte newHalteGrd(i,_T(""),0,i,3,INFINITY); m_HalteGrdArray.Add(newHalteGrd); } }
void CBUSWAYView::CreateNodeMatrix(int koridor, CHalteArray &halteArray) { ReFilterDB(); m_pSet->MoveFirst();
while(!m_pSet->IsEOF()) { if(m_pSet->m_koridor == koridor) { CHalte newHalte(m_pSet->m_ID, m_pSet->m_halte_name, m_pSet->m_koridor, m_pSet->m_node_num, m_pSet->m_node_code, m_pSet->m_node_dist);
halteArray.Add(newHalte); } m_pSet->MoveNext(); }; }
int CBUSWAYView::CalcDistance() { int retVal = 0; float dstKm = 0; int korSrc = atoi(m_HKorSrcOut); int korDst = atoi(m_HKorDstOut); int nodeSrc = atoi(m_HNodeSrcOut); int nodeDst = atoi(m_HNodeDstOut);
CString HSrcName = m_HalteArray[korSrc][nodeSrc].GetHalteName(); CString HDstName = m_HalteArray[korDst][nodeDst].GetHalteName();
retVal = DoGreedyAlg(); dstKm = (float)retVal / 1000.000; m_TotalCost.Format("%d\tMeter(s)\n%.3f\tKm",retVal,dstKm); PrintGeneralFacility(korDst,nodeDst); return retVal; }
int CBUSWAYView::GetTransHalte(int kor) { int retVal =0;
int k=0; for(int j=0; j<=m_HalteArray[kor].GetSize(); j++)
{ int a = m_HalteArray[kor][j].GetNodeCode(); if(a == 3) { k= k + 1; } } retVal = retVal + k;
return retVal; }
int CBUSWAYView::CalcDistInKoridor(int koridor, int nodeSrc, int nodeDst) { int retVal = 0; int dst = 0;
if(nodeSrc < nodeDst) { for(int i=nodeSrc; i<nodeDst; i++) { CString a = m_HalteArray[koridor][i].GetHalteName(); dst = m_HalteArray[koridor][i+1].GetDistance(); retVal = retVal + dst; } } else { for(int i=nodeSrc; i>nodeDst; i--) { dst = m_HalteArray[koridor][i].GetDistance();
retVal = retVal + dst; } } return retVal; }
char *NameTbl1[] = {"Harmoni","Dukuh Atas","Pecenongan","Juanda","Matraman","Senen","Terminal Pulo Gadung","Kp. Melayu","Dukuh Atas 2"};
void CBUSWAYView::CreateKoridorMatrix() { bool LookUpTblPath[NUM_TRANSHAL][NUM_TRANSHAL] = { {0,1,1,1,0,1,1,0,0}, {1,0,0,0,1,0,1,0,1}, {1,0,0,1,0,0,0,0,0}, {1,0,1,0,0,0,0,0,0}, {0,1,0,0,0,1,1,1,0}, {1,0,1,1,1,0,1,1,0}, {1,1,1,0,1,1,0,0,0}, {0,0,0,0,1,1,0,0,0}, {0,1,0,0,0,0,0,0,0} };
int LookUpTblKoridor[NUM_TRANSHAL][NUM_TRANSHAL] = { {0,1,3,3,0,2,2,0,1}, {1,0,0,0,4,0,4,0,1}, {3,0,0,2,0,0,0,0,0}, {3,0,3,0,0,0,0,0,0}, {0,4,0,0,0,5,4,5,0}, {2,0,2,2,2,0,2,5,0}, {2,4,2,2,4,2,0,0,0}, {0,0,0,0,5,5,0,0,0},
{1,6,0,0,0,0,0,0,0} };
/*bool LookUpTblPath[NUM_TRANSHAL][NUM_TRANSHAL] = { {0,1,1,1,0,1,1,0,0}, {1,0,0,0,1,0,1,0,1}, {1,0,0,1,0,1,1,0,0}, {1,0,1,0,0,1,1,0,0}, {0,1,0,0,0,1,1,1,0}, {1,0,1,1,1,0,1,1,0}, {1,1,1,0,1,1,0,0,0}, {0,0,0,0,1,1,0,0,0}, {0,1,0,0,0,0,0,0,0} };
int LookUpTblKoridor[NUM_TRANSHAL][NUM_TRANSHAL] = { {0,1,3,3,0,2,2,0,1}, {1,0,0,0,4,0,4,0,1}, {3,0,0,2,0,2,2,0,0}, {3,0,3,0,0,2,2,0,0}, {0,4,0,0,0,5,4,5,0}, {2,0,2,2,2,0,2,5,0}, {2,4,2,2,4,2,0,0,0}, {0,0,0,0,5,5,0,0,0}, {1,6,0,0,0,0,0,0,0} };
bool LookUpTblPath[NUM_TRANSHAL][NUM_TRANSHAL] = { {0,1,1,1,0,1,1,0,0,0}, {1,0,0,0,1,0,1,0,1,0}, {1,0,0,1,0,1,1,0,0,0},
{1,0,1,0,0,1,1,0,0,0}, {0,1,0,0,0,1,1,1,0,1}, {1,0,1,1,0,0,1,0,0,1}, {1,1,1,0,1,1,0,0,0,0}, {0,0,0,0,1,1,0,0,0,1}, {0,1,0,0,0,0,0,0,0,0}, {0,0,0,0,1,1,0,1,0,0} };
int LookUpTblKoridor[NUM_TRANSHAL][NUM_TRANSHAL] = { {0,1,3,3,0,2,2,0,1,0}, {1,0,0,0,4,0,4,0,1,0}, {3,0,0,3,0,2,2,0,0,0}, {3,0,3,0,0,2,2,0,0,0}, {0,4,0,0,0,5,4,5,0,5}, {2,0,2,2,0,0,2,0,0,2}, {2,4,2,2,4,2,0,0,0,0}, {0,0,0,0,5,5,0,0,0,5}, {1,6,0,0,0,0,0,0,0,0}, {0,0,0,0,5,2,0,5,0,0} };*/
for(int i=0;i
}
void CBUSWAYView::InitLookUpTblDist() { int i,j; for(i=0;i
void CBUSWAYView::CalcHTransDistance() { int i,j;
for(i=0; i
CString halteSrcName = NameTbl1[i]; for(j=0; j
if(halteKoridor != 0) { nodeSrc = GetHalteNode(halteKoridor,halteSrcName); nodeDst = GetHalteNode(halteKoridor,halteDstName); m_LookUpTblDistance[i][j] = CalcDistInKoridor(halteKoridor,nodeSrc,nodeDst); } } } int newKoridor = m_HalteGrdArray[i].GetKoridor(); m_HalteGrdArray[i].Set(i+1,halteSrcName,newKoridor,i,3,INFINITY); } }
int CBUSWAYView::GetHalteNode(int koridor, CString name) { int retVal = -1; for(int i=0; i<m_HalteArray[koridor].GetSize(); i++) { if(!strcmp(m_HalteArray[koridor][i].GetHalteName(), name)) { retVal = m_HalteArray[koridor][i].GetNode(); } } return retVal; }
void CBUSWAYView::ResetLabel() { int i,j; for(i=0; i
m_HalteGrdArray[i].SetLabel(tentative); m_HalteGrdArray[i].SetLength(INFINITY); m_HalteGrdArray[i].SetPredecessor(-1); }
for(i=0; i
int CBUSWAYView::DoGreedyAlg() { int retVal = 0; int KorSrc = atoi(m_HKorSrcOut); int KorDst = atoi(m_HKorDstOut); int NodeSrc = atoi(m_HNodeSrcOut); int NodeDst = atoi(m_HNodeDstOut);
if(KorDst == KorSrc) { // source and destination node in same corridor retVal = CalcDistInKoridor(KorDst, atoi(m_HNodeSrcOut), atoi(m_HNodeDstOut)); }
else { if(m_HalteArray[KorSrc][NodeSrc].GetNodeCode() != 3) { // source node is not transfer halte int i,j; int SrcCloserHalte[NUM_TRANSHAL]; int value[NUM_TRANSHAL]; int path[NUM_TRANSHAL][NUM_TRANSHAL];
int realSrcToCloseTransNode = -1; int realSrcNode = -1; int realDstNode = -1;
m_GreedyPath2[NUM_TRANSHAL] = -1; int NumCloserHToSource = GetCloserHalteInKor(KorSrc, NodeSrc); if(NumCloserHToSource != -1) { // the real source halte node realSrcNode = GetHalteNode(KorSrc, m_HNameSrcIn);
// copy closer halte array to another array so we can use for closer destination halte for(i=0; i
SrcCloserHalte[i] = -1; // initial for src closer halte SrcCloserHalte[i] = m_ClosHalte[i]; // copy }
int tempPathCode[NUM_TRANSHAL] = {-1}; int tempCount = -1;
for(i=0; i
realSrcToCloseTransNode = GetHalteNode(KorSrc, NameTbl1[SrcCloserHalte[i]]); distHalteToCloseSrc = CalcDistInKoridor(KorSrc, NodeSrc, realSrcToCloseTransNode); int NumCloserHToDest = GetCloserHalteInKor(KorDst, NodeDst); value[i] = CalcWithGreedy(NumCloserHToDest, SrcCloserHalte[i],KorDst,NodeDst,distHalteToCloseSrc); //copy path and reverse to get last node of greedy path
int temp=0; for(j=NUM_TRANSHAL-1; j>=0; j--) {
if(m_GreedyPath2[j] >= 0) {
path[i][j] = m_GreedyPath2[j]; tempCount = m_GreedyPath2[j]; temp++;
}
} tempPathCode[i] = tempCount; }
int min = INFINITY; int select = -1; int TheDist = 0; for(i=0; i
-1) if(tempPathCode[i] > -1) { //int code = path[i][0]; int code = tempPathCode[i];
realDstNode = GetHalteNode(KorSrc, NameTbl1[SrcCloserHalte[i]]); // source to close halte distance TheDist = CalcDistInKoridor(KorSrc, realSrcNode, realDstNode); //if(value[i] + TheDist < min) if(value[i] < min) { //TheDist = TheDist + value[i]; //min = value[i]; for(j=0; j
} } }
retVal = min; } } else { // source node is transfer halte, so this is done with distance matrix int initDestToSrc = 0; int Src = HalteToInt(KorSrc, NodeSrc);
ResetCloseHalte(); // Get the transfer halte who closer to destination halte int NumCloserHalte = GetCloserHalteInKor(KorDst, NodeDst);
retVal = CalcWithGreedy(NumCloserHalte, Src, KorDst, NodeDst, initDestToSrc);
} //Print Path PrintPath(m_HNameSrcIn, m_HNameDstIn); } return retVal; }
int CBUSWAYView::CalcWithGreedy(int closerHalte, int srcHalte, int korDst, int nodeDst, int distSrcToTrans) { int retVal = 0; int i,j, select; int minCost; int distance = 0;
int realNode = -1;
for(i=0; i
// reset all changed
at CArray ResetGreedyPath(); m_Cost[i] = SearchPath(srcHalte, m_ClosHalte[i]); if(m_Cost[i] > -1) { for(j=0; j
select = 0; minCost = INFINITY; for(i=0; i -1 && m_Cost[i] < minCost) if(m_Path2[i][0] > -1 && m_Cost[i] < minCost) { // From the greedy path get the real node code transfer halte int code = m_Path2[i][0]; realNode = GetHalteNode(korDst, NameTbl1[code]); distance = CalcDistInKoridor(korDst, realNode, nodeDst);
// from closer trans
halte to destination distance = distSrcToTrans + distance + m_Cost[i]; source to destination minCost = m_Cost[i] + distSrcToTrans; select = i;
// from
//get the path for(int k=0; k
} } }
for(i=0; i0) m_Path[i] = m_GreedyPath2[i-1]; }
retVal = distance; return retVal; }
int CBUSWAYView::SearchPath(int nodeSrc, int nodeDst) { int retVal = -1; int k, i;
// init source node m_HalteGrdArray[nodeSrc].SetLabel(permanent); m_HalteGrdArray[nodeSrc].SetLength(0);
if(nodeSrc == nodeDst) { return 0;
} else { k = nodeSrc; do { for(i=0; i
m_HalteGrdArray[i].SetLength((m_HalteGrdArray[k].GetLength() + m_LookUpTblDistance[k][i])); } } }
int min = INFINITY; k = 0; for(i=0; i
}while(k != nodeDst);
// Get the greedy path k = nodeDst; i=0; do { m_GreedyPath[i++] = k; k = m_HalteGrdArray[k].GetPredecessor(); }while(k >= 0);
int cost = 0; for(i=0; i= 0 && m_GreedyPath[i+1] != -1 && m_LookUpTblDistance[m_GreedyPath[i]][m_GreedyPath[i + 1]] >0) { cost = cost + m_LookUpTblDistance[m_GreedyPath[i]][m_GreedyPath[i + 1]]; } } retVal = cost; } return retVal; }
int CBUSWAYView::HalteToInt(int koridor, int node) { int retVal = -1; int i;
CString HalteName = m_HalteArray[koridor][node].GetHalteName();
for(i=0; i
int CBUSWAYView::GetCloserHalteInKor(int koridor, int node) { int retVal = -1; int i; int count = 0; int nNode = -1;
for(i=0; i<m_HalteArray[koridor].GetSize(); i++) { if(m_HalteArray[koridor][i].GetNodeCode() == 3) { nNode = m_HalteArray[koridor][i].GetNode(); m_ClosHalte[count] = HalteToInt(koridor, nNode); if(m_ClosHalte[count] >= 0) count++; } } retVal = count;
return retVal;
}
void CBUSWAYView::ResetGreedyPath() { for(int i=0; i
void CBUSWAYView::ResetCost() { for(int i=0; i
void CBUSWAYView::ResetCloseHalte() { for(int i=0; i
void CBUSWAYView::PrintPictureInfo() { CString text,text1,text2,text3,text4,text5,text6,text7;
text1
= "I, II, III, IV, V, VI, VII = Busway Koridor\n";
text2
= "\nTransfer Koridor:\n";
text3
= "1 : Harmoni (K-I)\t\t5 : Matraman (K-IV)\n";
text4
= "2 : Dukuh Atas (K-I)\t6 : Senen (K-V)\n";
text5
= "3 : Pecenongan (K-III)\t7 : P. Gadung (K-IV)\n";
text6
= "4 : Juanda (K-III)\t\t8 : Kp. Melayu (K-VII)\n";
text7
= "\t9 : Dukuh Atas 2 (K-VI)";
text = text1 + text2 + text3 + text4 + text5 + text6+ text7; //m_PictureInfo.Format("%s",text); m_PictureInfo = text; }
void CBUSWAYView::PrintPath(CString sourceName, CString dstName) { int i; CString pathName = _T(""); for(i=NUM_KORIDOR; i>=0; i--) { if(m_Path[i] > -1) { pathName = pathName + " - " + NameTbl1[m_Path[i]]; } } sourceName = "Jalur yang ditempuh :\n" + sourceName + pathName + " - " + dstName; m_Info = sourceName; //m_Info.Format("%s",sourceName); //UpdateData(false); }
void CBUSWAYView::PrintCost(int lenFromSrc, int lenFromDst) {
int i; int cost = 0; int cost1 = 0; int cost2 = 0; int count = 0; int distance[NUM_KORIDOR] = {0}; for(i=0; i -1 && m_Path[i+1] > -1) { distance[i] = m_LookUpTblDistance[m_Path[i]][m_Path[i+1]]; count++; } }
for(i=0; i
cost1 = lenFromSrc + cost - lenFromDst; cost2 = cost - lenFromSrc + lenFromDst; cost = (cost1 <= cost2) ? cost2 : cost1; //cost = lenFromSrc + cost - lenFromDst; cost = (cost<0) ? -cost : cost; m_TotalCost.Format("%d", cost); //UpdateData(false); }
void CBUSWAYView::PrintMatrixAdj() { CString tempString = ""; for(int i=0; i
{ for(int j=0; j
m_MatrixOutName = "Adjacency Matrices"; }
void CBUSWAYView::PrintMatrixDist() { CString tempString = ""; for(int i=0; i
m_MatrixOutName = "Distance Matrices (Meter(s))"; }
void CBUSWAYView::PrintMatrixTransHal() { CString tempString = ""; for(int i=0; i
m_MatrixOutName = "Transfer Halte Matrices (Transfer Koridor Number)"; }
void CBUSWAYView::PrintNullMatrix() { CString tempString = ""; m_MatrixOutLabel = ""; m_MatrixOut = ""; for(int i=0; i
tempString.Format("%d",0); m_MatrixOut += tempString + "\t"; } //tempString.Format("%d",i+1); m_MatrixOut += "\n"; tempString.Format("%d",i+1); m_MatrixOutLabel += tempString + "\t"; }
m_MatrixOutName = "9x9 Null Matrices"; UpdateData(false); }
void CBUSWAYView::OnBtnAdj() { // TODO: Add your control notification handler code here m_MatrixOutLabel = ""; m_MatrixOut = ""; PrintMatrixAdj(); UpdateData(false); }
void CBUSWAYView::OnBtnDist() { // TODO: Add your control notification handler code here m_MatrixOutLabel = ""; m_MatrixOut = ""; PrintMatrixDist(); UpdateData(false); }
void CBUSWAYView::OnBtnTranshal() { // TODO: Add your control notification handler code here m_MatrixOutLabel = ""; m_MatrixOut = ""; PrintMatrixTransHal(); UpdateData(false); }
void CBUSWAYView::PrintGeneralFacility(int koridor, int node) { int idx = 0; CString textToPrint = "";
idx = GetDBIndex(koridor, node);
ReFilterDB(); m_pSet->MoveFirst(); while(!m_pSet->IsEOF()) { if(m_pSet->m_ID == idx) { textToPrint = m_pSet->m_general; } m_pSet->MoveNext(); }; m_GeneralFac = textToPrint; }
int CBUSWAYView::GetDBIndex(int koridor, int node) {
int retVal = 0; ReFilterDB(); m_pSet->MoveFirst();
while(!m_pSet->IsEOF()) { if(m_pSet->m_koridor == koridor) { if(m_pSet->m_node_num == node) { retVal = m_pSet->m_ID; } } m_pSet->MoveNext(); }; return retVal; }
void CBUSWAYView::PrintTicketPrice(int koridor) { time_t osBinaryTime; time(&osBinaryTime); int minutes; int hours;
CTime theTime(osBinaryTime); hours = theTime.GetHour(); minutes = theTime.GetMinute();
if(hours >= 5 && hours <=7) {
m_InfoPrice.Format("Rp. %d",TPrice[0]); } else if(hours >7 && hours <= 22) { m_InfoPrice.Format("Rp. %d",TPrice[1]); } else { m_InfoPrice = "Halte is Currently CLOSED"; } }
LAMPIRAN B
jkt_busway ID
koridor 1 2 3 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
halte_name 1 Terminal Blok M 1 Mesjid Agung 1 Gelora Bung Karno 1 Polda Metro Jaya 1 Bendungan Hilir 1 Karet 1 Setia Budi 1 Dukuh Atas 1 Dukuh Atas 2 1 Tosari 1 Bunderan HI 1 Sarinah 1 Bank Indonesia 1 Monumen Nasional 1 Harmoni 1 Sawah Besar 1 Mangga Besar 1 Olimo 1 Glodok 1 Stasiun Kota Jakarta 2 Terminal Pulo Gadung 2 Bermis 2 Pulomas 2 ASMI 2 Pedongkelan 2 Cempaka Timur 2 RS Islam 2 Cempaka Tengah 2 Pasar Cempaka Putih 2 Rawa Selatan 2 Galur 2 Senen 2 Atrium 2 RSPAD 2 Deplu 2 Gambir 1 2 Istiqlal 2 Juanda 2 Pecenongan 2 Harmoni 2 Gambir 2 2 Balai Kota
Page 1
2/28/2009
node_num 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
node_code
node_dist 2 2 2 2 2 2 2 3 3 2 2 2 2 2 3 2 2 2 2 2 3 2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 3 3 3 2 2
0 645 735 650 650 735 600 735 0 900 735 735 735 735 900 600 735 600 650 735 0 850 700 600 700 700 750 600 600 600 600 850 458 458 458 458 458 458 458 850 1100 700
jkt_busway general_fac Blok M Plaza,Blok M Mall Mesjid Agung Al‐Azhar,S Sudirman Place,Stadion Bursa Efek Jakarta,SCBD, Pasar Benhil,RS. Jakarta, Sudirman Square Office T Hotel Sahid Jaya Wisma BNI 46,Hotel Sang ‐ Hotel The Westin Plaza Indonesia,Grand Hy Sarinah,Graha Mataram, Gedung Bank Indonesia Tugu Monas,Taman Silan Duta Merlin Plaza Gajah Mada Gajah Mada Square,Plaza SMUN 2,Hotel Mercure,Jl Pasar Glodok,Harco Glod Stasiun KA JakartaKota, Terminal Bus Pulogadung ‐ Korean World Center Pul ‐ ‐ Mega Mall ITC Cempaka Pasar Sumur Batu ‐ Pasar Cempaka Putih Pasar Gembrong,Pasar G ‐ Stasiun KA Senen,Termin Plaza Atrium ‐ ‐ Stasiun KA Gambir,Tugu Mesjid Istiqlal,Gereja Kha ‐ ‐ Duta Merlin,Plaza Harmo ‐ Kantor Gubernur DKI Jak
general1
general2
Page 2
2/28/2009
jkt_busway ID
koridor 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
halte_name 2 Kwitang 2 Senen 3 Terminal Kali Deres 3 Pesakih 3 Sumur Bor 3 Rawa Buaya 3 Jembatan Baru 3 Dispenda 3 Jembatan Gantung 3 Taman Kota 3 Indosiar 3 Jelambar 3 Harmoni 3 Pecenongan 3 Juanda 3 Pasar Baru 4 Terminal Pulo Gadung 4 Pasar Pulo Gadung 4 TU Gas 4 Layur 4 Pemuda Rawamangun 4 Velodrome 4 Sunan Giri 4 UNJ 4 Pramuka BPKP 4 Pramuka Lia 4 Utan Kayu 4 Pasar Genjing 4 Matraman 4 Manggarai 4 Pasar Rumput 4 Halimun 4 Dukuh Atas 4 Dukuh Atas 2 5 Ancol 5 Pademangan 5 Gunung Sahari Mangga 5 Jembatan Merah 5 Pasar Baru Timur 5 Budi Utomo 5 Senen 5 Pal Putih
Page 3
node_num 23 24 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1 2 3 4 5 6 7 8
2/28/2009 node_code 2 3 2 2 2 2 2 2 2 2 2 2 3 3 3 2 3 2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 3 3 2 2 2 2 2 2 3 2
node_dist 450 450 0 1100 800 900 700 900 1100 900 3700 1400 5000 850 700 650 0 850 750 800 800 650 650 650 650 650 550 650 850 950 600 700 750 0 0 900 600 1100 1500 650 1200 700
jkt_busway general_fac Museum Kebangkitan Na ‐ Terminal Bus Kalideres Daan Mogot Plaza ‐ Plaza Cengkareng ‐ ‐ ‐ ‐ ‐ ‐ Duta Merlin,Plaza Harmo ‐ ‐ Pasar Baru,Gedung Kese Terminal Bus Pulogadung Pasar Pulogadung ‐ ‐ ‐ Stadion Velodrome Rawa Pasar Sunan Giri ‐ ‐ ‐ ‐ ‐ ‐ Pasar Pramuka,Pasar Bur Pasaraya Manggarai,Pasa Museum Sasmita Loka ‐ ‐ Taman Impian Jaya Ancol Pasar Marina Mangga Du ‐ Pasar Pangeran Jayakart Golden Truly Super Store ‐ Stasiun KA Senen,Termin ‐
general1
general2
Page 4
2/28/2009
jkt_busway ID
koridor 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
halte_name 5 Kramat Sention NU 5 Salemba UI 5 Salemba Carolus 5 Matraman 5 Tegalan 5 Slamet Riyadi 5 Kebon Pala 5 Pasar Jatinegara 5 Kp. Melayu 6 Ragunan 6 Dep Pertanian 6 SMK 57 6 Jati Padang 6 Pejaten 6 Buncit Indah 6 Warung Jati 6 Imigrasi 6 Duren Tiga 6 Mampang Prapatan 6 Kuningan Timur 6 Patra Kuningan 6 Depkes 6 GOR Sumantri 6 Karet Kuningan 6 Kuningan Madya AINI 6 Setia Budi AINI 6 Dukuh Atas 2 6 Dukuh Atas 6 Latuharhary 6 Seta Budi Utara 6 Kuningan Madya AINI 7 Terminal Kampung Ram 7 Tanah Merdeka 7 Fly Over Raya Bogor 7 RS Harapan Bunda 7 Ps Induk Kramat Jati 7 Ps Kramat Jati 7 PGC (Cililitan) 7 BKN 7 Cawang UKI 7 BNN 7 Cawang Otista
Page 5
2/28/2009
node_num 9 10 11 12 13 14 15 16 17 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 1 2 3 4 5 6 7 8 9 10 11
node_code 2 2 2 3 2 2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2
node_dist 600 850 600 800 800 850 700 800 850 0 800 600 650 650 600 800 650 650 700 650 600 650 750 600 700 650 0 1 650 1100 900 0 950 950 950 1000 2700 900 950 800 750 650
jkt_busway general_fac
general1
general2
‐ Pasar Kenari Baru,Pasar ‐ ‐ Mall Graha Matraman ‐ ‐ Plaza Jatinegara,Pasar Jat Terminal Bus Kampung Kebon Binatang Ragunan Bumi Perkemahan Ragun SMK Negeri 57 Jakarta,ST Mall Pejaten,Kantor Lura SMK Negeri 47 Jakarta,A RS. JMC,Wisma Bakrie Bu STIE Dharma Bumi Puter SMU Negeri 60 Jakarta,K Kantor Lurah Duren Tiga, Kantor Lurah Mampang Gedung Infome Kantor Lurah Kuningan Ti Kedutaan Besar Gedung RNI,Bal ‐ Apartemen Puri Casablan Kedutaan Besar Gedung Bina M ‐ ‐ Kantor Lurah Karet Kunin Gedung Graha Apartemen Setiabudi,Ap Gedung Menar ‐ ‐ Plaza Menteng,Aparteme Museum Peru ‐ ‐ Terminal Bus Kampung R Makro Pasar Rebo SMU Teladan,Gedung AK SMU Kuntum Wijaya Kus Pasar Induk Kramat Jati,S Kramat Jati Indah Plaza,P Pusat Grosir Cililitan,SMK SMU Negeri 14 Jakarta,S SMK Bhakti 2,Universitas Pegadaian,Gedung Waski Kantor Lurah Bidara Cina, Gedung Balai H
Page 6
2/28/2009
jkt_busway ID
koridor 128 129 130
halte_name 7 Gelanggang Remaja 7 Bidara Cina 7 Kp. Melayu
node_num 12 13 14
Page 7
2/28/2009 node_code 2 2 3
node_dist 800 800 600
jkt_busway general_fac general1 SMP Vincentius,Hotel Fid Kantor Lurah Tebet Timu Terminal Kampung Mela Gedung Sandip
general2
Page 8
2/28/2009