// File: Kei18[P]pibt/./src/graph/pd.cpp
// Function: PD::init()
void PD::init() {
  std::string file_pd = filename + ".pd";  // pickup and delivery
  std::ifstream file(file_pd);
  if (!file) {
    std::cout << "error@PD::init, file "
              << file_pd
              << " does not exist" << "\n";
    std::exit(1);
  }

  std::string line;
  std::smatch results;
  int w = getW();
  int h = getH();
  int j = 0;  // height
  int id = 0;
  std::string s;
  Node* v;

  std::regex r_obj   = std::regex(R"([@T])");
  std::regex r_pickup = std::regex(R"([psa])");  // pickup loc.
  std::regex r_deliv  = std::regex(R"([dsa])");  // delivery loc.
  std::regex r_end    = std::regex(R"([ea])");  // end loc.

  while (getline(file, line)) {
    // error check, width
    if (line.size() != w) {
      std::cout << "error@PD::init, "
                << "width is invalid, should be " << w <<  "\n";
      std::exit(1);
    }

    for (int i = 0; i < w; ++i) {
      s = line[i];
      id = j * w + i;
      if (std::regex_match(s, results, r_obj)) continue;

      if (!existNode(id)) {
        std::cout << "error@PD::init, "
                  << "corresponding node does not exist, " << id << "\n";
        std::exit(1);
      }
      v = getNode(id);  // target node

      if (std::regex_match(s, results, r_pickup)) {
        pickup.push_back(v);
      }
      if (std::regex_match(s, results, r_pickup)) {
        delivery.push_back(v);
      }
      if (std::regex_match(s, results, r_end)) {
        endpoints.push_back(v);
      }
    }
    ++j;
  }
  file.close();

  // height check
  if (j != h) {
    std::cout << "error@PD::init, "
              << "height is invalid, shoudl be " << h <<  "\n";
    std::exit(1);
  }

  if (pickup.empty() || delivery.empty() || endpoints.empty()) {
    std::cout << "error@TP::init, file "
              << file_pd << ".pd is not for MAPD, "
              << "there is no pickup/delivery/end location" << "\n";
    std::exit(1);
  }

  setStartGoal();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x410, %rsp            # imm = 0x410
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rsi
movq %rsi, -0x350(%rbp)
addq $0xa0, %rsi
leaq 0x6c8bc(%rip), %rdx     # 0xb51e4
leaq -0x28(%rbp), %rdi
movq %rdi, -0x348(%rbp)
callq 0x3aec0
movq -0x348(%rbp), %rsi
leaq -0x230(%rbp), %rdi
movl $0x8, %edx
callq 0x8780
jmp 0x48952
movq -0x230(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x230(%rbp,%rax), %rdi
callq 0x8260
movb %al, -0x351(%rbp)
jmp 0x48972
movb -0x351(%rbp), %al
testb $0x1, %al
jne 0x48981
jmp 0x48a1f
movq 0xb8610(%rip), %rdi     # 0x100f98
leaq 0x6c859(%rip), %rsi     # 0xb51e8
callq 0x84d0
movq %rax, -0x360(%rbp)
jmp 0x4899d
movq -0x360(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x8470
movq %rax, -0x368(%rbp)
jmp 0x489b6
movq -0x368(%rbp), %rdi
leaq 0x6a968(%rip), %rsi     # 0xb332c
callq 0x84d0
movq %rax, -0x370(%rbp)
jmp 0x489d2
movq -0x370(%rbp), %rdi
leaq 0x6abd7(%rip), %rsi     # 0xb35b7
callq 0x84d0
jmp 0x489e7
movl $0x1, %edi
callq 0x85d0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
jmp 0x49141
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
jmp 0x49135
leaq -0x260(%rbp), %rdi
callq 0x86b0
leaq -0x280(%rbp), %rdi
callq 0xd430
jmp 0x48a39
movq -0x350(%rbp), %rdi
movq (%rdi), %rax
movq (%rax), %rax
callq *%rax
movl %eax, -0x374(%rbp)
jmp 0x48a50
movq -0x350(%rbp), %rdi
movl -0x374(%rbp), %eax
movl %eax, -0x284(%rbp)
movq (%rdi), %rax
movq 0x8(%rax), %rax
callq *%rax
movl %eax, -0x378(%rbp)
jmp 0x48a74
movl -0x378(%rbp), %eax
movl %eax, -0x288(%rbp)
movl $0x0, -0x28c(%rbp)
movl $0x0, -0x290(%rbp)
leaq -0x2b0(%rbp), %rdi
callq 0x86b0
leaq 0x6c757(%rip), %rsi     # 0xb51fe
leaq -0x2d8(%rbp), %rdi
movl $0x10, %edx
callq 0xd390
jmp 0x48aba
leaq 0x6c742(%rip), %rsi     # 0xb5203
leaq -0x2f8(%rbp), %rdi
movl $0x10, %edx
callq 0xd390
jmp 0x48ad4
leaq 0x6c72e(%rip), %rsi     # 0xb5209
leaq -0x318(%rbp), %rdi
movl $0x10, %edx
callq 0xd390
jmp 0x48aee
leaq 0x6c71a(%rip), %rsi     # 0xb520f
leaq -0x338(%rbp), %rdi
movl $0x10, %edx
callq 0xd390
jmp 0x48b08
jmp 0x48b0a
leaq -0x230(%rbp), %rdi
leaq -0x260(%rbp), %rsi
callq 0x80f0
movq %rax, -0x380(%rbp)
jmp 0x48b26
movq -0x380(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x8620
movb %al, -0x381(%rbp)
jmp 0x48b44
movb -0x381(%rbp), %al
testb $0x1, %al
jne 0x48b53
jmp 0x48f05
leaq -0x260(%rbp), %rdi
callq 0x83b0
movslq -0x284(%rbp), %rcx
cmpq %rcx, %rax
je 0x48c8e
movq 0xb8422(%rip), %rdi     # 0x100f98
leaq 0x6c697(%rip), %rsi     # 0xb5214
callq 0x84d0
movq %rax, -0x390(%rbp)
jmp 0x48b8b
movq -0x390(%rbp), %rdi
leaq 0x6c68c(%rip), %rsi     # 0xb5225
callq 0x84d0
movq %rax, -0x398(%rbp)
jmp 0x48ba7
movq -0x398(%rbp), %rdi
movl -0x284(%rbp), %esi
callq 0x8860
movq %rax, -0x3a0(%rbp)
jmp 0x48bc2
movq -0x3a0(%rbp), %rdi
leaq 0x6a9e7(%rip), %rsi     # 0xb35b7
callq 0x84d0
jmp 0x48bd7
movl $0x1, %edi
callq 0x85d0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
jmp 0x49129
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
jmp 0x4911d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
jmp 0x49111
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
jmp 0x49105
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
jmp 0x490f9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
jmp 0x490ed
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
leaq -0x338(%rbp), %rdi
callq 0xd6d0
jmp 0x490ed
movl $0x0, -0x33c(%rbp)
movl -0x33c(%rbp), %eax
cmpl -0x284(%rbp), %eax
jge 0x48ef1
movslq -0x33c(%rbp), %rsi
leaq -0x260(%rbp), %rdi
callq 0x8930
movq %rax, -0x3a8(%rbp)
jmp 0x48cc6
movq -0x3a8(%rbp), %rax
movsbl (%rax), %esi
leaq -0x2b0(%rbp), %rdi
callq 0x87d0
jmp 0x48cde
movl -0x28c(%rbp), %eax
movl -0x284(%rbp), %ecx
imull %ecx, %eax
movl -0x33c(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x290(%rbp)
leaq -0x2b0(%rbp), %rdi
leaq -0x280(%rbp), %rsi
leaq -0x2d8(%rbp), %rdx
xorl %ecx, %ecx
callq 0xd470
movb %al, -0x3a9(%rbp)
jmp 0x48d1f
movb -0x3a9(%rbp), %al
testb $0x1, %al
jne 0x48d2b
jmp 0x48d30
jmp 0x48edd
movq -0x350(%rbp), %rdi
movl -0x290(%rbp), %esi
callq 0x3c7d0
movb %al, -0x3aa(%rbp)
jmp 0x48d4a
movb -0x3aa(%rbp), %al
testb $0x1, %al
jne 0x48dc8
jmp 0x48d56
movq 0xb823b(%rip), %rdi     # 0x100f98
leaq 0x6c4b0(%rip), %rsi     # 0xb5214
callq 0x84d0
movq %rax, -0x3b8(%rbp)
jmp 0x48d72
movq -0x3b8(%rbp), %rdi
leaq 0x6c4c2(%rip), %rsi     # 0xb5242
callq 0x84d0
movq %rax, -0x3c0(%rbp)
jmp 0x48d8e
movq -0x3c0(%rbp), %rdi
movl -0x290(%rbp), %esi
callq 0x8860
movq %rax, -0x3c8(%rbp)
jmp 0x48da9
movq -0x3c8(%rbp), %rdi
leaq 0x6a800(%rip), %rsi     # 0xb35b7
callq 0x84d0
jmp 0x48dbe
movl $0x1, %edi
callq 0x85d0
movq -0x350(%rbp), %rdi
movl -0x290(%rbp), %esi
callq 0x3c590
movq %rax, -0x3d0(%rbp)
jmp 0x48de3
movq -0x3d0(%rbp), %rax
movq %rax, -0x2b8(%rbp)
leaq -0x2b0(%rbp), %rdi
leaq -0x280(%rbp), %rsi
leaq -0x2f8(%rbp), %rdx
xorl %ecx, %ecx
callq 0xd470
movb %al, -0x3d1(%rbp)
jmp 0x48e15
movb -0x3d1(%rbp), %al
testb $0x1, %al
jne 0x48e21
jmp 0x48e3f
movq -0x350(%rbp), %rdi
addq $0xc0, %rdi
leaq -0x2b8(%rbp), %rsi
callq 0x3f490
jmp 0x48e3d
jmp 0x48e3f
leaq -0x2b0(%rbp), %rdi
leaq -0x280(%rbp), %rsi
leaq -0x2f8(%rbp), %rdx
xorl %ecx, %ecx
callq 0xd470
movb %al, -0x3d2(%rbp)
jmp 0x48e63
movb -0x3d2(%rbp), %al
testb $0x1, %al
jne 0x48e6f
jmp 0x48e8d
movq -0x350(%rbp), %rdi
addq $0xd8, %rdi
leaq -0x2b8(%rbp), %rsi
callq 0x3f490
jmp 0x48e8b
jmp 0x48e8d
leaq -0x2b0(%rbp), %rdi
leaq -0x280(%rbp), %rsi
leaq -0x338(%rbp), %rdx
xorl %ecx, %ecx
callq 0xd470
movb %al, -0x3d3(%rbp)
jmp 0x48eb1
movb -0x3d3(%rbp), %al
testb $0x1, %al
jne 0x48ebd
jmp 0x48edb
movq -0x350(%rbp), %rdi
addq $0xf0, %rdi
leaq -0x2b8(%rbp), %rsi
callq 0x3f490
jmp 0x48ed9
jmp 0x48edb
jmp 0x48edd
movl -0x33c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x33c(%rbp)
jmp 0x48c98
movl -0x28c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28c(%rbp)
jmp 0x48b0a
leaq -0x230(%rbp), %rdi
callq 0x8120
jmp 0x48f13
movl -0x28c(%rbp), %eax
cmpl -0x288(%rbp), %eax
je 0x48f93
movq 0xb8070(%rip), %rdi     # 0x100f98
leaq 0x6c2e5(%rip), %rsi     # 0xb5214
callq 0x84d0
movq %rax, -0x3e0(%rbp)
jmp 0x48f3d
movq -0x3e0(%rbp), %rdi
leaq 0x6c31b(%rip), %rsi     # 0xb5266
callq 0x84d0
movq %rax, -0x3e8(%rbp)
jmp 0x48f59
movq -0x3e8(%rbp), %rdi
movl -0x288(%rbp), %esi
callq 0x8860
movq %rax, -0x3f0(%rbp)
jmp 0x48f74
movq -0x3f0(%rbp), %rdi
leaq 0x6a635(%rip), %rsi     # 0xb35b7
callq 0x84d0
jmp 0x48f89
movl $0x1, %edi
callq 0x85d0
movq -0x350(%rbp), %rdi
addq $0xc0, %rdi
callq 0x3ec00
testb $0x1, %al
jne 0x48fdd
movq -0x350(%rbp), %rdi
addq $0xd8, %rdi
callq 0x3ec00
testb $0x1, %al
jne 0x48fdd
movq -0x350(%rbp), %rdi
addq $0xf0, %rdi
callq 0x3ec00
testb $0x1, %al
jne 0x48fdd
jmp 0x49069
movq 0xb7fb4(%rip), %rdi     # 0x100f98
leaq 0x6c299(%rip), %rsi     # 0xb5284
callq 0x84d0
movq %rax, -0x3f8(%rbp)
jmp 0x48ff9
movq -0x3f8(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x8470
movq %rax, -0x400(%rbp)
jmp 0x49012
movq -0x400(%rbp), %rdi
leaq 0x6c27a(%rip), %rsi     # 0xb529a
callq 0x84d0
movq %rax, -0x408(%rbp)
jmp 0x4902e
movq -0x408(%rbp), %rdi
leaq 0x6c274(%rip), %rsi     # 0xb52b0
callq 0x84d0
movq %rax, -0x410(%rbp)
jmp 0x4904a
movq -0x410(%rbp), %rdi
leaq 0x6a55f(%rip), %rsi     # 0xb35b7
callq 0x84d0
jmp 0x4905f
movl $0x1, %edi
callq 0x85d0
movq -0x350(%rbp), %rdi
movq (%rdi), %rax
movq 0x68(%rax), %rax
callq *%rax
jmp 0x4907b
leaq -0x338(%rbp), %rdi
callq 0xd6d0
leaq -0x318(%rbp), %rdi
callq 0xd6d0
leaq -0x2f8(%rbp), %rdi
callq 0xd6d0
leaq -0x2d8(%rbp), %rdi
callq 0xd6d0
leaq -0x2b0(%rbp), %rdi
callq 0x8330
leaq -0x280(%rbp), %rdi
callq 0xd6b0
leaq -0x260(%rbp), %rdi
callq 0x8330
leaq -0x230(%rbp), %rdi
callq 0x8170
leaq -0x28(%rbp), %rdi
callq 0x8330
addq $0x410, %rsp            # imm = 0x410
popq %rbp
retq
leaq -0x318(%rbp), %rdi
callq 0xd6d0
leaq -0x2f8(%rbp), %rdi
callq 0xd6d0
leaq -0x2d8(%rbp), %rdi
callq 0xd6d0
leaq -0x2b0(%rbp), %rdi
callq 0x8330
leaq -0x280(%rbp), %rdi
callq 0xd6b0
leaq -0x260(%rbp), %rdi
callq 0x8330
leaq -0x230(%rbp), %rdi
callq 0x8170
leaq -0x28(%rbp), %rdi
callq 0x8330
movq -0x238(%rbp), %rdi
callq 0x8880
nopw %cs:(%rax,%rax)