// File: /workspace/github_cpp_makefile_star2_O2/harry830622[P]floorplanner/src/floorplanner.cpp
// Function: Floorplanner::Floorplanner(Database const&, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, bool, bool)
Floorplanner::Floorplanner(const Database& database, double alpha,
                           const string& sa_mode, bool is_verbose,
                           bool is_drawing)
    : database_(database),
      alpha_(alpha),
      sa_mode_(sa_mode),
      is_verbose_(is_verbose),
      is_drawing_(is_drawing),
      min_area_(numeric_limits<double>::max()),
      max_area_(0.0),
      min_wirelength_(numeric_limits<double>::max()),
      max_wirelength_(0.0),
      average_area_(0.0),
      average_wirelength_(0.0),
      average_uphill_cost_(0.0),
      best_floorplan_(Floorplan(database_.num_macros(), is_drawing)),
      drawing_(Json::object()) {
  const int num_macros = database_.num_macros();
  const int num_perturbations = num_macros * num_macros;
  Floorplan floorplan(best_floorplan_);

  double total_area = 0.0;
  double total_wirelength = 0.0;
  for (int i = 0; i < num_perturbations; ++i) {
    floorplan.Perturb(database_);
    floorplan.Pack(database_);
    const double area = floorplan.area();
    const double wirelength = floorplan.wirelength();
    if (area < min_area_) {
      min_area_ = area;
    }
    if (area > max_area_) {
      max_area_ = area;
    }
    if (wirelength < min_wirelength_) {
      min_wirelength_ = wirelength;
    }
    if (wirelength > max_wirelength_) {
      max_wirelength_ = wirelength;
    }
    total_area += area;
    total_wirelength += wirelength;
  }
  average_area_ = total_area / num_perturbations;
  average_wirelength_ = total_wirelength / num_perturbations;

  double total_uphill_cost = 0.0;
  int num_uphills = 0;
  double adaptive_alpha = alpha_ / 4.0;
  double adaptive_beta = (1.0 - alpha_) / 4.0;
  double last_cost =
      ComputeCost(best_floorplan_, adaptive_alpha, adaptive_beta);
  for (int i = 0; i < num_perturbations; ++i) {
    floorplan.Perturb(database_);
    floorplan.Pack(database_);
    double cost = ComputeCost(floorplan, adaptive_alpha, adaptive_beta);
    double delta_cost = cost - last_cost;
    if (delta_cost > 0) {
      ++num_uphills;
      total_uphill_cost += delta_cost;
    }
    last_cost = cost;
  }
  average_uphill_cost_ = total_uphill_cost / num_uphills;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movl %r8d, %ebp
movl %ecx, %r14d
movq %rdi, %r12
movq %rsi, (%rdi)
movsd %xmm0, 0x8(%rdi)
leaq 0x10(%rdi), %rbx
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x74d0
movb %r14b, 0x30(%r12)
movb %bpl, 0x31(%r12)
movsd 0xbba5(%rip), %xmm0     # 0x1b6d8
movupd %xmm0, 0x38(%r12)
movabsq $0x7fefffffffffffff, %rax # imm = 0x7FEFFFFFFFFFFFFF
movq %rax, 0x48(%r12)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x50(%r12)
movupd %xmm0, 0x60(%r12)
movq (%r12), %rdi
callq 0x8d3c
leaq 0x70(%r12), %r14
movzbl %bpl, %edx
movq %r14, %rdi
movl %eax, %esi
callq 0xab88
leaq 0x118(%r12), %r13
movq %r13, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xd1f4
movq (%r12), %rdi
callq 0x8d3c
movl %eax, %r15d
movq %r13, (%rsp)
movq %rbx, 0x8(%rsp)
leaq 0x40(%rsp), %rdi
movq %r14, %rsi
callq 0x11ef8
leaq 0x50(%r12), %rbx
imull %r15d, %r15d
xorpd %xmm1, %xmm1
leaq 0x40(%rsp), %r13
movl %r15d, %ebp
subl $0x1, %ebp
jb 0xfc66
movapd %xmm1, 0x10(%rsp)
movq (%r12), %rsi
movq %r13, %rdi
callq 0xacf6
movq (%r12), %rsi
movq %r13, %rdi
callq 0xb566
movq %r13, %rdi
callq 0xacd8
movapd %xmm0, 0x20(%rsp)
movq %r13, %rdi
callq 0xace4
movsd 0x38(%r12), %xmm1
movapd 0x20(%rsp), %xmm2
ucomisd %xmm2, %xmm1
jbe 0xfc19
movsd %xmm2, 0x38(%r12)
ucomisd 0x40(%r12), %xmm2
jbe 0xfc2f
movapd 0x20(%rsp), %xmm1
movsd %xmm1, 0x40(%r12)
movsd 0x48(%r12), %xmm1
ucomisd %xmm0, %xmm1
jbe 0xfc43
movsd %xmm0, 0x48(%r12)
ucomisd (%rbx), %xmm0
movapd 0x10(%rsp), %xmm1
jbe 0xfc53
movsd %xmm0, (%rbx)
movapd 0x20(%rsp), %xmm2
unpcklpd %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0]
addpd %xmm2, %xmm1
jmp 0xfbc2
cvtsi2sd %r15d, %xmm0
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
divpd %xmm0, %xmm1
movupd %xmm1, 0x58(%r12)
movsd 0x8(%r12), %xmm0
movsd 0xba57(%rip), %xmm2     # 0x1b6e0
movsd 0xba57(%rip), %xmm1     # 0x1b6e8
subsd %xmm0, %xmm1
mulsd %xmm2, %xmm0
mulsd %xmm2, %xmm1
movq %r12, %rdi
movq %r14, %rsi
movsd %xmm0, 0x38(%rsp)
movsd %xmm1, 0x30(%rsp)
callq 0xfdc6
movapd %xmm0, %xmm1
xorl %ebx, %ebx
leaq 0x40(%rsp), %r13
xorpd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
subl $0x1, %r15d
jb 0xfd37
movsd %xmm1, 0x20(%rsp)
movq (%r12), %rsi
movq %r13, %rdi
callq 0xacf6
movq (%r12), %rsi
movq %r13, %rdi
callq 0xb566
movq %r12, %rdi
movq %r13, %rsi
movsd 0x38(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
callq 0xfdc6
movapd %xmm0, %xmm1
subsd 0x20(%rsp), %xmm1
xorl %eax, %eax
ucomisd 0xb9d8(%rip), %xmm1     # 0x1b6f0
seta %cl
jbe 0xfd2d
movsd 0x10(%rsp), %xmm2
addsd %xmm1, %xmm2
movsd %xmm2, 0x10(%rsp)
movb %cl, %al
addl %eax, %ebx
movapd %xmm0, %xmm1
jmp 0xfcc9
cvtsi2sd %ebx, %xmm0
movsd 0x10(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x68(%r12)
leaq 0x40(%rsp), %rdi
callq 0x11fb2
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xfd8f
movq %rax, %r12
movq 0x8(%rsp), %rbx
movq (%rsp), %r13
jmp 0xfda5
movq %rax, %r12
jmp 0xfda5
movq %rax, %r12
jmp 0xfdad
movq %rax, %r12
jmp 0xfdb5
jmp 0xfd8f
jmp 0xfd8f
jmp 0xfd8f
jmp 0xfd8f
movq %rax, %r12
movq 0x8(%rsp), %rbx
movq (%rsp), %r13
leaq 0x40(%rsp), %rdi
callq 0x11fb2
movq %r13, %rdi
callq 0xd290
movq %r14, %rdi
callq 0x11fb2
movq %rbx, %rdi
callq 0x7758
movq %r12, %rdi
callq 0x7660
nop