// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rsi, %rbx
movl %edi, %r14d
leaq 0x3c0c(%rip), %rax      # 0x5120
xorl %ecx, %ecx
xorl %edx, %edx
movl $0xbf800000, (%rax,%rdx,4) # imm = 0xBF800000
incq %rdx
cmpq $0x15, %rdx
jne 0x1518
incq %rcx
addq $0x54, %rax
cmpq $0x15, %rcx
jne 0x1516
movl $0x427c0000, 0x3d95(%rip) # imm = 0x427C0000
movl $0x41d00000, %eax       # imm = 0x41D00000
movl %eax, 0x3d32(%rip)      # 0x527c
movl $0x42a60000, 0x3d40(%rip) # imm = 0x42A60000
movl $0x41980000, 0x3cc6(%rip) # imm = 0x41980000
movl $0x42880000, 0x3cd8(%rip) # imm = 0x42880000
movl $0x42600000, 0x3c56(%rip) # imm = 0x42600000
movl $0x42ba0000, 0x3c68(%rip) # imm = 0x42BA0000
movl $0x424c0000, 0x3bb6(%rip) # imm = 0x424C0000
movl $0x42040000, 0x3da4(%rip) # imm = 0x42040000
movabsq $0x4200000042680000, %rcx # imm = 0x4200000042680000
movq %rcx, 0x3e9b(%rip)      # 0x543c
movl $0x425c0000, 0x3f41(%rip) # imm = 0x425C0000
movl $0x422c0000, 0x3f2f(%rip) # imm = 0x422C0000
movl $0x423c0000, 0x3ec1(%rip) # imm = 0x423C0000
movl $0x42aa0000, 0x3ed3(%rip) # imm = 0x42AA0000
movl $0x42e60000, 0x3f75(%rip) # imm = 0x42E60000
movl $0x42700000, 0x3dc3(%rip) # imm = 0x42700000
movl $0x420c0000, 0x3da5(%rip) # imm = 0x420C0000
movabsq $0x42600000425c0000, %rcx # imm = 0x42600000425C0000
movq %rcx, 0x3e04(%rip)      # 0x53fc
movl $0x42340000, %ecx       # imm = 0x42340000
movl %ecx, 0x3f9d(%rip)      # 0x55a0
movl $0x41f00000, 0x4037(%rip) # imm = 0x41F00000
movl %ecx, 0x3ff5(%rip)      # 0x5608
movabsq $0x428a000041f00000, %rcx # imm = 0x428A000041F00000
movq %rcx, 0x4080(%rip)      # 0x56a4
movl $0x42900000, 0x40ce(%rip) # imm = 0x42900000
movl $0x41b00000, 0x411c(%rip) # imm = 0x41B00000
movl %eax, 0x4122(%rip)      # 0x5760
movl $0x41d80000, 0x416c(%rip) # imm = 0x41D80000
movq 0x3ab9(%rip), %rdi      # 0x5108
movq 0x8(%rdi), %rdx
leaq 0x19d6(%rip), %rcx      # 0x3030
xorl %r15d, %r15d
movl $0x5, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x3a97(%rip), %rdi      # 0x5108
movq 0x28(%rdi), %rdx
addq $0x20, %rdi
leaq 0x19b6(%rip), %rcx      # 0x3036
movl $0x7, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x3a74(%rip), %rdi      # 0x5108
movq 0x48(%rdi), %rdx
addq $0x40, %rdi
leaq 0x199b(%rip), %rcx      # 0x303e
movl $0xb, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x3a51(%rip), %rdi      # 0x5108
movq 0x68(%rdi), %rdx
addq $0x60, %rdi
leaq 0x1984(%rip), %rcx      # 0x304a
movl $0x6, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x3a2e(%rip), %rdi      # 0x5108
movq 0x88(%rdi), %rdx
subq $-0x80, %rdi
leaq 0x1965(%rip), %rcx      # 0x3051
movl $0x6, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x3a08(%rip), %rdi      # 0x5108
movq 0xa8(%rdi), %rdx
addq $0xa0, %rdi
leaq 0x1943(%rip), %rcx      # 0x3058
movl $0xb, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x39df(%rip), %rdi      # 0x5108
movq 0xc8(%rdi), %rdx
addq $0xc0, %rdi
leaq 0x1926(%rip), %rcx      # 0x3064
movl $0x8, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x39b6(%rip), %rdi      # 0x5108
movq 0xe8(%rdi), %rdx
addq $0xe0, %rdi
leaq 0x1906(%rip), %rcx      # 0x306d
movl $0x7, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x398d(%rip), %rdi      # 0x5108
movq 0x108(%rdi), %rdx
addq $0x100, %rdi            # imm = 0x100
leaq 0x18e5(%rip), %rcx      # 0x3075
movl $0x6, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x3964(%rip), %rdi      # 0x5108
movq 0x128(%rdi), %rdx
addq $0x120, %rdi            # imm = 0x120
leaq 0x18c3(%rip), %rcx      # 0x307c
movl $0x8, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x393b(%rip), %rdi      # 0x5108
movq 0x148(%rdi), %rdx
addq $0x140, %rdi            # imm = 0x140
leaq 0x18a3(%rip), %rcx      # 0x3085
movl $0xa, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x3912(%rip), %rdi      # 0x5108
movq 0x168(%rdi), %rdx
addq $0x160, %rdi            # imm = 0x160
leaq 0x1885(%rip), %rcx      # 0x3090
movl $0x7, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x38e9(%rip), %rdi      # 0x5108
movq 0x188(%rdi), %rdx
addq $0x180, %rdi            # imm = 0x180
leaq 0x1864(%rip), %rcx      # 0x3098
movl $0x9, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x38c0(%rip), %rdi      # 0x5108
movq 0x1a8(%rdi), %rdx
addq $0x1a0, %rdi            # imm = 0x1A0
leaq 0x1845(%rip), %rcx      # 0x30a2
movl $0x6, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x3897(%rip), %rdi      # 0x5108
movq 0x1c8(%rdi), %rdx
addq $0x1c0, %rdi            # imm = 0x1C0
leaq 0x1823(%rip), %rcx      # 0x30a9
movl $0x8, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x386e(%rip), %rdi      # 0x5108
movq 0x1e8(%rdi), %rdx
addq $0x1e0, %rdi            # imm = 0x1E0
leaq 0x1803(%rip), %rcx      # 0x30b2
movl $0xa, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x3845(%rip), %rdi      # 0x5108
movq 0x208(%rdi), %rdx
addq $0x200, %rdi            # imm = 0x200
leaq 0x17e5(%rip), %rcx      # 0x30bd
movl $0x7, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x381c(%rip), %rdi      # 0x5108
movq 0x228(%rdi), %rdx
addq $0x220, %rdi            # imm = 0x220
leaq 0x17c4(%rip), %rcx      # 0x30c5
movl $0x8, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x37f3(%rip), %rdi      # 0x5108
movq 0x248(%rdi), %rdx
addq $0x240, %rdi            # imm = 0x240
leaq 0x17a4(%rip), %rcx      # 0x30ce
movl $0x5, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x37ca(%rip), %rdi      # 0x5108
movq 0x268(%rdi), %rdx
addq $0x260, %rdi            # imm = 0x260
leaq 0x1781(%rip), %rcx      # 0x30d4
movl $0x5, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x37a1(%rip), %rdi      # 0x5108
movq 0x288(%rdi), %rdx
addq $0x280, %rdi            # imm = 0x280
leaq 0x175e(%rip), %rcx      # 0x30da
movl $0x6, %r8d
xorl %esi, %esi
callq 0x1150
cmpl $0x2, %r14d
jne 0x1a9f
movq 0x376e(%rip), %rdi      # 0x5108
xorl %r14d, %r14d
cmpq %rdi, 0x376c(%rip)      # 0x5110
setne %r12b
je 0x19fd
movq 0x8(%rbx), %rsi
callq 0x1050
movl $0x0, %r15d
testl %eax, %eax
je 0x1a00
movl $0x20, %r13d
xorl %r15d, %r15d
incq %r15
movq 0x3740(%rip), %rax      # 0x5110
movq 0x3731(%rip), %rdi      # 0x5108
subq %rdi, %rax
sarq $0x5, %rax
cmpq %rax, %r15
setb %r12b
jae 0x19fd
addq %r13, %rdi
movq 0x8(%rbx), %rsi
callq 0x1050
addq $0x20, %r13
testl %eax, %eax
jne 0x19c6
jmp 0x1a00
xorl %r15d, %r15d
testb %r12b, %r12b
jne 0x1a96
movq 0x35c0(%rip), %r14      # 0x4fd0
leaq 0x16ca(%rip), %rsi      # 0x30e1
movl $0x5, %edx
movq %r14, %rdi
callq 0x1120
movq 0x8(%rbx), %rbx
testq %rbx, %rbx
je 0x1a49
movq %rbx, %rdi
callq 0x1070
movq 0x3594(%rip), %rdi      # 0x4fd0
movq %rbx, %rsi
movq %rax, %rdx
callq 0x1120
jmp 0x1a61
movq (%r14), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x1170
movq 0x3568(%rip), %rbx      # 0x4fd0
leaq 0x1678(%rip), %rsi      # 0x30e7
movl $0x38, %edx
movq %rbx, %rdi
callq 0x1120
leaq 0x169d(%rip), %rsi      # 0x3120
movl $0x4a, %edx
movq %rbx, %rdi
callq 0x1120
movl $0x1, %r14d
testb %r12b, %r12b
je 0x1c77
leaq -0xd0(%rbp), %rbx
movq %rbx, %rdi
callq 0x1e1c
leaq -0x30(%rbp), %rsi
movl %r15d, (%rsi)
leaq -0x2c(%rbp), %rdx
movl $0x1, (%rdx)
movq %rbx, %rdi
callq 0x1ea4
xorl %r14d, %r14d
movq %rbx, %rdi
callq 0x1fd2
incl %r14d
cmpl $0x1, %eax
je 0x1aca
cmpl $0x3, %eax
je 0x1b5e
cmpl $0x2, %eax
jne 0x1bd4
movq 0x34e1(%rip), %rdi      # 0x4fd0
leaq 0x1675(%rip), %rsi      # 0x316b
movl $0x33, %edx
callq 0x1120
movq -0x80(%rbp), %rbx
movq %rbx, -0x70(%rbp)
movq 0x34c1(%rip), %rdi      # 0x4fd0
leaq 0x1689(%rip), %rsi      # 0x319f
movl $0x26, %edx
callq 0x1120
leaq 0x1c(%rbx), %rdi
testq %rbx, %rbx
cmoveq %rbx, %rdi
callq 0x1498
xorl %ebx, %ebx
movq -0x70(%rbp), %rax
testq %rax, %rax
je 0x1b4e
movq 0x8(%rax), %rdi
testq %rdi, %rdi
je 0x1b4e
movq %rdi, -0x70(%rbp)
addq $0x1c, %rdi
jmp 0x1b50
xorl %edi, %edi
testq %rdi, %rdi
je 0x1b78
callq 0x1498
incl %ebx
jmp 0x1b32
movq 0x346b(%rip), %rdi      # 0x4fd0
leaq 0x166c(%rip), %rsi      # 0x31d8
movl $0x2b, %edx
callq 0x1120
jmp 0x1bd4
movq 0x3451(%rip), %rdi      # 0x4fd0
leaq 0x1640(%rip), %rsi      # 0x31c6
movl $0x11, %edx
callq 0x1120
movq 0x3439(%rip), %rdi      # 0x4fd0
movl %ebx, %esi
callq 0x1180
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x10f0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1040
movq %rax, %rdi
callq 0x10c0
leaq -0xd0(%rbp), %rdi
callq 0x2346
movq 0x33f5(%rip), %rdi      # 0x4fd0
leaq 0x1622(%rip), %rsi      # 0x3204
movl $0x1b, %edx
callq 0x1120
movl %r14d, %esi
movq 0x33da(%rip), %rdi      # 0x4fd0
callq 0x10b0
leaq 0x151c(%rip), %rsi      # 0x311e
movl $0x1, %edx
movq %rax, %rdi
callq 0x1120
cmpl $0x0, -0x38(%rbp)
jne 0x1c8c
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x1c23
callq 0x1130
movq -0xa0(%rbp), %rdi
testq %rdi, %rdi
je 0x1c3e
movq -0x90(%rbp), %rsi
subq %rdi, %rsi
callq 0x1110
movq -0xb8(%rbp), %rdi
testq %rdi, %rdi
je 0x1c59
movq -0xa8(%rbp), %rsi
subq %rdi, %rsi
callq 0x1110
movq -0xd0(%rbp), %rdi
testq %rdi, %rdi
je 0x1c74
movq -0xc0(%rbp), %rsi
subq %rdi, %rsi
callq 0x1110
xorl %r14d, %r14d
movl %r14d, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1719(%rip), %rdi      # 0x33ac
leaq 0x15f5(%rip), %rsi      # 0x328f
leaq 0x1724(%rip), %rcx      # 0x33c5
movl $0x274, %edx            # imm = 0x274
callq 0x10a0
jmp 0x1cb5
jmp 0x1cb5
jmp 0x1cb5
jmp 0x1cb5
jmp 0x1cb5
movq %rax, %rbx
leaq -0xd0(%rbp), %rdi
callq 0x23bc
movq %rbx, %rdi
callq 0x1190