// File: rilutham[P]gotojakarta/go-to-jakarta.cpp
// Function: main
int main( int argc, char *argv[] )
{
  // Creating Map of West Java
  for(int i=0; i<MAX_CITIES; i++)
    for(int j=0; j<MAX_CITIES; j++)
      WestJavaMap[i][j]=-1.0;

  // Define distance between two cities 
  // From Plat Z
  WestJavaMap[Pangandaran][Banjar]=63;
  WestJavaMap[Banjar][Ciamis]=26;
  WestJavaMap[Banjar][Kuningan]=83;
  WestJavaMap[Ciamis][Tasikmalaya]=19;
  WestJavaMap[Ciamis][Kuningan]=68;
  WestJavaMap[Tasikmalaya][Garut]=56;
  WestJavaMap[Tasikmalaya][Bandung]=93;
  WestJavaMap[Garut][Bandung]=51;
  WestJavaMap[Sumedang][Bandung]=33;

  // From Plat E
  WestJavaMap[Kuningan][Cirebon]=32;
  WestJavaMap[Kuningan][Majalengka]=58;
  WestJavaMap[Cirebon][Indramayu]=55;
  WestJavaMap[Cirebon][Majalengka]=43;
  WestJavaMap[Majalengka][Sumedang]=47;
  WestJavaMap[Majalengka][Subang]=85;
  WestJavaMap[Indramayu][Karawang]=115;

  // From Plat D
  WestJavaMap[Bandung][Subang]=60;
  WestJavaMap[Bandung][Cimahi]=35;
  WestJavaMap[Cimahi][Purwakarta]=55;
  WestJavaMap[Cimahi][Cianjur]=56;

  // From Plat T
  WestJavaMap[Subang][Purwakarta]=45;
  WestJavaMap[Purwakarta][Karawang]=30;
  WestJavaMap[Karawang][Bekasi]=45;

  // From Plat F
  WestJavaMap[Cianjur][Sukabumi]=30;
  WestJavaMap[Cianjur][Bogor]=69;
  WestJavaMap[Sukabumi][Bogor]=72;
  WestJavaMap[Bogor][Depok]=22;

  // From Plat B
  WestJavaMap[Depok][Jakarta]=26;
  WestJavaMap[Bekasi][Jakarta]=27;

  // City names
  CityNames[Garut].assign("Garut");
  CityNames[Jakarta].assign("Jakarta");
  CityNames[Tasikmalaya].assign("Tasikmalaya");
  CityNames[Ciamis].assign("Ciamis");
  CityNames[Banjar].assign("Banjar");
  CityNames[Pangandaran].assign("Pangandaran");
  CityNames[Sumedang].assign("Sumedang");
  CityNames[Bandung].assign("Bandung");
  CityNames[Cimahi].assign("Cimahi");
  CityNames[Kuningan].assign("Kuningan");
  CityNames[Majalengka].assign("Majalengka");
  CityNames[Cirebon].assign("Cirebon");
  CityNames[Indramayu].assign("Indramayu");
  CityNames[Subang].assign("Subang");
  CityNames[Karawang].assign("Karawang");
  CityNames[Purwakarta].assign("Purwakarta");
  CityNames[Cianjur].assign("Cianjur");
  CityNames[Sukabumi].assign("Sukabumi");
  CityNames[Bogor].assign("Bogor");
  CityNames[Depok].assign("Depok");
  CityNames[Bekasi].assign("Bekasi");

  ENUM_CITIES initCity = Garut;
  if(argc == 2)
  {
    bool found = false;
    for(size_t i=0; i<CityNames.size(); i++)
      if(CityNames[i].compare(argv[1])==0)
      {
        initCity = (ENUM_CITIES)i;
        found = true;
        break;
      }
    if(not found)
    {
      cout << "Kota "<<argv[1]<<" tidak ditemukan pada peta Jawa Barat, silahkan ulangi!\n";
      cout << "Gunakan kapital pada huruf pertama nama kota. Contoh: Garut, Pangandaran.\n";
      return(1);
    }
  }

  // An instance of A* search class
	AStarSearch<PathSearchNode> astarsearch;

	unsigned int SearchCount = 0;
	const unsigned int NumSearches = 1;

	while(SearchCount < NumSearches)
	{
		// Create a start state
		PathSearchNode nodeStart;
		nodeStart.city = initCity;

		// Define the goal state, always Jakarta!
		PathSearchNode nodeEnd;
		nodeEnd.city = Jakarta;

		// Set Start and goal states
		astarsearch.SetStartAndGoalStates( nodeStart, nodeEnd );

		unsigned int SearchState;
		unsigned int SearchSteps = 0;

		do
		{
			SearchState = astarsearch.SearchStep();
			SearchSteps++;

	#if DEBUG_LISTS

			cout << "Steps:" << SearchSteps << "\n";

			int len = 0;

			cout << "Open:\n";
			PathSearchNode *p = astarsearch.GetOpenListStart();
			while( p )
			{
				len++;
	#if !DEBUG_LIST_LENGTHS_ONLY
				((PathSearchNode *)p)->PrintNodeInfo();
	#endif
				p = astarsearch.GetOpenListNext();

			}
			cout << "Open list has " << len << " nodes\n";

			len = 0;

			cout << "Closed:\n";
			p = astarsearch.GetClosedListStart();
			while( p )
			{
				len++;
	#if !DEBUG_LIST_LENGTHS_ONLY
				p->PrintNodeInfo();
	#endif
				p = astarsearch.GetClosedListNext();
			}

			cout << "Closed list has " << len << " nodes\n";
	#endif

		}
		while( SearchState == AStarSearch<PathSearchNode>::SEARCH_STATE_SEARCHING );

		if( SearchState == AStarSearch<PathSearchNode>::SEARCH_STATE_SUCCEEDED )
		{
			cout << "Pencarian rute terpendek menuju Jakarta ditemukan!\n";
      PathSearchNode *node = astarsearch.GetSolutionStart();
      cout << "Berikut kota-kota yang harus dilalui:\n";
      int steps = 0;
      node->PrintNodeInfo();
      for( ;; )
      {
        node = astarsearch.GetSolutionNext();
        if( !node ) break;
        node->PrintNodeInfo();
        steps ++;
      };
      cout << "Langkah Solusi : " << steps << endl;
      // Once you're done with the solution you can free the nodes up
			astarsearch.FreeSolutionNodes();
		}
		else if( SearchState == AStarSearch<PathSearchNode>::SEARCH_STATE_FAILED )
		{
			cout << "Search terminated. Did not find goal state\n";
		}
		// Display the number of loops the search went through
		cout << "Jumlah langkah pencarian : " << SearchSteps << "\n";
		SearchCount ++;
		astarsearch.EnsureMemoryFreed();
	}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
cmpl $0x15, -0x14(%rbp)
jge 0x279e
movl $0x0, -0x18(%rbp)
cmpl $0x15, -0x18(%rbp)
jge 0x2791
movslq -0x14(%rbp), %rcx
leaq 0x89c2(%rip), %rax      # 0xb130
imulq $0x54, %rcx, %rcx
addq %rcx, %rax
movslq -0x18(%rbp), %rcx
movss 0x491f(%rip), %xmm0     # 0x70a0
movss %xmm0, (%rax,%rcx,4)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x275d
jmp 0x2793
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x2750
movss 0x48f6(%rip), %xmm0     # 0x709c
movss %xmm0, 0x8b36(%rip)     # 0xb2e4
movss 0x489e(%rip), %xmm0     # 0x7054
movss %xmm0, 0x8ace(%rip)     # 0xb28c
movss 0x48d2(%rip), %xmm0     # 0x7098
movss %xmm0, 0x8ad6(%rip)     # 0xb2a4
movss 0x48be(%rip), %xmm0     # 0x7094
movss %xmm0, 0x8a56(%rip)     # 0xb234
movss 0x48aa(%rip), %xmm0     # 0x7090
movss %xmm0, 0x8a62(%rip)     # 0xb250
movss 0x4826(%rip), %xmm0     # 0x701c
movss %xmm0, 0x89da(%rip)     # 0xb1d8
movss 0x4886(%rip), %xmm0     # 0x708c
movss %xmm0, 0x89e6(%rip)     # 0xb1f4
movss 0x4872(%rip), %xmm0     # 0x7088
movss %xmm0, 0x892e(%rip)     # 0xb14c
movss 0x485e(%rip), %xmm0     # 0x7084
movss %xmm0, 0x8b16(%rip)     # 0xb344
movss 0x484a(%rip), %xmm0     # 0x7080
movss %xmm0, 0x8c12(%rip)     # 0xb450
movss 0x4836(%rip), %xmm0     # 0x707c
movss %xmm0, 0x8bfe(%rip)     # 0xb44c
movss 0x480e(%rip), %xmm0     # 0x7064
movss %xmm0, 0x8c9e(%rip)     # 0xb4fc
movss 0x4812(%rip), %xmm0     # 0x7078
movss %xmm0, 0x8c86(%rip)     # 0xb4f4
movss 0x47fe(%rip), %xmm0     # 0x7074
movss %xmm0, 0x8c12(%rip)     # 0xb490
movss 0x478a(%rip), %xmm0     # 0x7010
movss %xmm0, 0x8c1e(%rip)     # 0xb4ac
movss 0x47da(%rip), %xmm0     # 0x7070
movss %xmm0, 0x8cba(%rip)     # 0xb558
movss 0x47c6(%rip), %xmm0     # 0x706c
movss %xmm0, 0x8b02(%rip)     # 0xb3b0
movss 0x47b2(%rip), %xmm0     # 0x7068
movss %xmm0, 0x8ade(%rip)     # 0xb39c
movss 0x479e(%rip), %xmm0     # 0x7064
movss %xmm0, 0x8b3e(%rip)     # 0xb40c
movss 0x4746(%rip), %xmm0     # 0x701c
movss %xmm0, 0x8b32(%rip)     # 0xb410
movss 0x477a(%rip), %xmm0     # 0x7060
movss %xmm0, 0x8cc2(%rip)     # 0xb5b0
movss 0x470e(%rip), %xmm0     # 0x7004
movss %xmm0, 0x8d56(%rip)     # 0xb654
movss 0x475a(%rip), %xmm0     # 0x7060
movss %xmm0, 0x8d0a(%rip)     # 0xb618
movss 0x46ee(%rip), %xmm0     # 0x7004
movss %xmm0, 0x8d96(%rip)     # 0xb6b4
movss 0x4736(%rip), %xmm0     # 0x705c
movss %xmm0, 0x8d8a(%rip)     # 0xb6b8
movss 0x4722(%rip), %xmm0     # 0x7058
movss %xmm0, 0x8dce(%rip)     # 0xb70c
movss 0x46c2(%rip), %xmm0     # 0x7008
movss %xmm0, 0x8e16(%rip)     # 0xb764
movss 0x46fe(%rip), %xmm0     # 0x7054
movss %xmm0, 0x8e12(%rip)     # 0xb770
movss 0x46ea(%rip), %xmm0     # 0x7050
movss %xmm0, 0x8e56(%rip)     # 0xb7c4
leaq 0x87a3(%rip), %rdi      # 0xb118
xorl %eax, %eax
movl %eax, %esi
callq 0x30b0
movq %rax, %rdi
leaq 0x4780(%rip), %rsi      # 0x7108
callq 0x21c0
leaq 0x8784(%rip), %rdi      # 0xb118
movl $0x1, %esi
callq 0x30b0
movq %rax, %rdi
leaq 0x4766(%rip), %rsi      # 0x710e
callq 0x21c0
leaq 0x8764(%rip), %rdi      # 0xb118
movl $0x2, %esi
callq 0x30b0
movq %rax, %rdi
leaq 0x474e(%rip), %rsi      # 0x7116
callq 0x21c0
leaq 0x8744(%rip), %rdi      # 0xb118
movl $0x3, %esi
callq 0x30b0
movq %rax, %rdi
leaq 0x473a(%rip), %rsi      # 0x7122
callq 0x21c0
leaq 0x8724(%rip), %rdi      # 0xb118
movl $0x4, %esi
callq 0x30b0
movq %rax, %rdi
leaq 0x4721(%rip), %rsi      # 0x7129
callq 0x21c0
leaq 0x8704(%rip), %rdi      # 0xb118
movl $0x5, %esi
callq 0x30b0
movq %rax, %rdi
leaq 0x4708(%rip), %rsi      # 0x7130
callq 0x21c0
leaq 0x86e4(%rip), %rdi      # 0xb118
movl $0x6, %esi
callq 0x30b0
movq %rax, %rdi
leaq 0x46f4(%rip), %rsi      # 0x713c
callq 0x21c0
leaq 0x86c4(%rip), %rdi      # 0xb118
movl $0x7, %esi
callq 0x30b0
movq %rax, %rdi
leaq 0x46dd(%rip), %rsi      # 0x7145
callq 0x21c0
leaq 0x86a4(%rip), %rdi      # 0xb118
movl $0x8, %esi
callq 0x30b0
movq %rax, %rdi
leaq 0x46c5(%rip), %rsi      # 0x714d
callq 0x21c0
leaq 0x8684(%rip), %rdi      # 0xb118
movl $0x9, %esi
callq 0x30b0
movq %rax, %rdi
leaq 0x46ac(%rip), %rsi      # 0x7154
callq 0x21c0
leaq 0x8664(%rip), %rdi      # 0xb118
movl $0xa, %esi
callq 0x30b0
movq %rax, %rdi
leaq 0x4695(%rip), %rsi      # 0x715d
callq 0x21c0
leaq 0x8644(%rip), %rdi      # 0xb118
movl $0xb, %esi
callq 0x30b0
movq %rax, %rdi
leaq 0x4680(%rip), %rsi      # 0x7168
callq 0x21c0
leaq 0x8624(%rip), %rdi      # 0xb118
movl $0xc, %esi
callq 0x30b0
movq %rax, %rdi
leaq 0x4668(%rip), %rsi      # 0x7170
callq 0x21c0
leaq 0x8604(%rip), %rdi      # 0xb118
movl $0xd, %esi
callq 0x30b0
movq %rax, %rdi
leaq 0x4652(%rip), %rsi      # 0x717a
callq 0x21c0
leaq 0x85e4(%rip), %rdi      # 0xb118
movl $0xe, %esi
callq 0x30b0
movq %rax, %rdi
leaq 0x4639(%rip), %rsi      # 0x7181
callq 0x21c0
leaq 0x85c4(%rip), %rdi      # 0xb118
movl $0xf, %esi
callq 0x30b0
movq %rax, %rdi
leaq 0x4622(%rip), %rsi      # 0x718a
callq 0x21c0
leaq 0x85a4(%rip), %rdi      # 0xb118
movl $0x10, %esi
callq 0x30b0
movq %rax, %rdi
leaq 0x460d(%rip), %rsi      # 0x7195
callq 0x21c0
leaq 0x8584(%rip), %rdi      # 0xb118
movl $0x11, %esi
callq 0x30b0
movq %rax, %rdi
leaq 0x45f5(%rip), %rsi      # 0x719d
callq 0x21c0
leaq 0x8564(%rip), %rdi      # 0xb118
movl $0x12, %esi
callq 0x30b0
movq %rax, %rdi
leaq 0x45de(%rip), %rsi      # 0x71a6
callq 0x21c0
leaq 0x8544(%rip), %rdi      # 0xb118
movl $0x13, %esi
callq 0x30b0
movq %rax, %rdi
leaq 0x45c4(%rip), %rsi      # 0x71ac
callq 0x21c0
leaq 0x8524(%rip), %rdi      # 0xb118
movl $0x14, %esi
callq 0x30b0
movq %rax, %rdi
leaq 0x45aa(%rip), %rsi      # 0x71b2
callq 0x21c0
movl $0x0, -0x1c(%rbp)
cmpl $0x2, -0x8(%rbp)
jne 0x2ceb
movb $0x0, -0x1d(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x108(%rbp)
leaq 0x84dc(%rip), %rdi      # 0xb118
callq 0x3170
movq %rax, %rcx
movq -0x108(%rbp), %rax
cmpq %rcx, %rax
jae 0x2c92
movq -0x28(%rbp), %rsi
leaq 0x84bd(%rip), %rdi      # 0xb118
callq 0x30b0
movq %rax, %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x2050
cmpl $0x0, %eax
jne 0x2c82
movq -0x28(%rbp), %rax
movl %eax, -0x1c(%rbp)
movb $0x1, -0x1d(%rbp)
jmp 0x2c92
jmp 0x2c84
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x2c2a
testb $0x1, -0x1d(%rbp)
jne 0x2ce9
movq 0x8331(%rip), %rdi      # 0xafd0
leaq 0x4513(%rip), %rsi      # 0x71b9
callq 0x20f0
movq %rax, %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x20f0
movq %rax, %rdi
leaq 0x44fa(%rip), %rsi      # 0x71bf
callq 0x20f0
movq 0x82ff(%rip), %rdi      # 0xafd0
leaq 0x4520(%rip), %rsi      # 0x71f8
callq 0x20f0
movl $0x1, -0x4(%rbp)
jmp 0x2f88
jmp 0x2ceb
leaq -0xc8(%rbp), %rdi
callq 0x3190
movl $0x0, -0xcc(%rbp)
movl $0x1, -0xd0(%rbp)
cmpl $0x1, -0xcc(%rbp)
jae 0x2f75
leaq -0xd4(%rbp), %rdi
callq 0x30d0
jmp 0x2d26
movl -0x1c(%rbp), %eax
movl %eax, -0xd4(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x30d0
jmp 0x2d3d
movl $0x1, -0xe8(%rbp)
leaq -0xc8(%rbp), %rdi
leaq -0xd4(%rbp), %rsi
leaq -0xe8(%rbp), %rdx
callq 0x3260
jmp 0x2d63
movl $0x0, -0xf0(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x33a0
movl %eax, -0x10c(%rbp)
jmp 0x2d81
movl -0x10c(%rbp), %eax
movl %eax, -0xec(%rbp)
movl -0xf0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf0(%rbp)
cmpl $0x1, -0xec(%rbp)
je 0x2d6d
cmpl $0x2, -0xec(%rbp)
jne 0x2ee6
movq 0x8217(%rip), %rdi      # 0xafd0
leaq 0x4483(%rip), %rsi      # 0x7243
callq 0x20f0
jmp 0x2dc7
leaq -0xc8(%rbp), %rdi
callq 0x3c60
movq %rax, -0x118(%rbp)
jmp 0x2ddc
movq -0x118(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq 0x81df(%rip), %rdi      # 0xafd0
leaq 0x447f(%rip), %rsi      # 0x7277
callq 0x20f0
jmp 0x2dff
movl $0x0, -0xfc(%rbp)
movq -0xf8(%rbp), %rdi
callq 0x26c0
jmp 0x2e17
jmp 0x2e19
leaq -0xc8(%rbp), %rdi
callq 0x3ca0
movq %rax, -0x120(%rbp)
jmp 0x2e2e
movq -0x120(%rbp), %rax
movq %rax, -0xf8(%rbp)
cmpq $0x0, -0xf8(%rbp)
jne 0x2e6b
jmp 0x2e8a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x3dd0
jmp 0x2f94
movq -0xf8(%rbp), %rdi
callq 0x26c0
jmp 0x2e79
movl -0xfc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xfc(%rbp)
jmp 0x2e19
movq 0x813f(%rip), %rdi      # 0xafd0
leaq 0x4406(%rip), %rsi      # 0x729e
callq 0x20f0
movq %rax, -0x128(%rbp)
jmp 0x2ea6
movq -0x128(%rbp), %rdi
movl -0xfc(%rbp), %esi
callq 0x21a0
movq %rax, -0x130(%rbp)
jmp 0x2ec1
movq -0x130(%rbp), %rdi
movq 0x80f1(%rip), %rsi      # 0xafc0
callq 0x2120
jmp 0x2ed6
leaq -0xc8(%rbp), %rdi
callq 0x3d00
jmp 0x2ee4
jmp 0x2f08
cmpl $0x3, -0xec(%rbp)
jne 0x2f06
movq 0x80da(%rip), %rdi      # 0xafd0
leaq 0x43b3(%rip), %rsi      # 0x72b0
callq 0x20f0
jmp 0x2f04
jmp 0x2f06
jmp 0x2f08
movq 0x80c1(%rip), %rdi      # 0xafd0
leaq 0x43c6(%rip), %rsi      # 0x72dc
callq 0x20f0
movq %rax, -0x138(%rbp)
jmp 0x2f24
movq -0x138(%rbp), %rdi
movl -0xf0(%rbp), %esi
callq 0x2140
movq %rax, -0x140(%rbp)
jmp 0x2f3f
movq -0x140(%rbp), %rdi
leaq 0x42a9(%rip), %rsi      # 0x71f6
callq 0x20f0
jmp 0x2f54
movl -0xcc(%rbp), %eax
incl %eax
movl %eax, -0xcc(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x3d90
jmp 0x2f70
jmp 0x2d0b
movl $0x0, -0x4(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x3dd0
movl -0x4(%rbp), %eax
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
movq -0xe0(%rbp), %rdi
callq 0x21b0