// File: /workspace/github_cpp_makefile_star2_O2/iu-vail[P]iprimal/iPrimal.cpp
// Function: Primal::GreedyApprox2(std::vector<unsigned int, std::allocator<unsigned int>>&)
void
Primal::GreedyApprox2(vector<uint>& _asgn){

  _asgn.clear();
  _asgn.resize(row_size);
  set<uint> mem_rows;
  set<uint> mem_cols;
  priority_queue<
                pair<cell, double>,
                vector<pair<cell,double> >,
                less_comp<cell>
		> col_mins;

  //column-wise searching, push the smallest of each col in priority queue
  for(uint j=0; j<col_size; j++){
    double min_val = std::numeric_limits<double>::infinity(); 
    uint min_row = row_size;
    for(uint i=0; i<row_size; i++){
      if(orig_matrix[i][j] < min_val){
	min_val = orig_matrix[i][j];
	min_row = i;	
      }
    }
    cell c;
    c.row_idx = min_row;
    c.col_idx = j;
    col_mins.push(pair<cell, double>(c, min_val));
  }

  //assign those global minimals (conflicted) first
  while(!col_mins.empty()){
    pair<cell, double> p = col_mins.top();
    col_mins.pop();
    if(mem_rows.find(p.first.row_idx) == mem_rows.end()){
      mem_rows.insert(p.first.row_idx);
      mem_cols.insert(p.first.col_idx);
      _asgn[p.first.row_idx] = p.first.col_idx;
    }
  }

  //then assign other un-assigned
  //column-wise searching
  for(uint j=0; j<col_size; j++){
    if(mem_cols.find(j) == mem_cols.end()){
      double min_val = std::numeric_limits<double>::infinity(); 
      uint min_row = row_size;
      for(uint i=0; i<row_size; i++){
        if(orig_matrix[i][j] < min_val &&
      		mem_rows.find(i) == mem_rows.end()){
	  min_val = orig_matrix[i][j];
	  min_row = i;	
        }
      }
      _asgn[min_row] = j;
      mem_rows.insert(min_row);
    }//if
  }//for

  //double check if the assignment is meaningful
  set<uint> test(_asgn.begin(), _asgn.end());
  assert(test.size()==row_size);
  _cout("Approximate assignment: "<<endl);
  DisplayVec<uint>(_asgn);

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rsi, %rcx
movq %rdi, %rbx
movq (%rsi), %rax
cmpq %rax, 0x8(%rsi)
je 0x365e
movq %rax, 0x8(%rcx)
movl (%rbx), %esi
movq %rcx, 0x10(%rsp)
movq %rcx, %rdi
callq 0x4e7c
leaq 0xb0(%rsp), %r14
andl $0x0, (%r14)
andq $0x0, 0x8(%r14)
movq %r14, 0x10(%r14)
movq %r14, 0x18(%r14)
andq $0x0, 0x20(%r14)
leaq 0x80(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
xorpd %xmm0, %xmm0
leaq 0x50(%rsp), %r15
movupd %xmm0, 0x9(%r15)
movapd %xmm0, (%r15)
xorl %r13d, %r13d
leaq 0x20(%rsp), %r12
movl 0x4(%rbx), %eax
cmpq %rax, %r13
jae 0x372e
movl (%rbx), %eax
movq 0xb0(%rbx), %rcx
xorl %esi, %esi
movsd 0x59d1(%rip), %xmm0     # 0x90b0
movl %eax, %edx
cmpq %rsi, %rax
je 0x3707
movq (%rcx), %rdi
movsd (%rdi,%r13,8), %xmm1
ucomisd %xmm1, %xmm0
cmoval %esi, %edx
minsd %xmm0, %xmm1
incq %rsi
addq $0x18, %rcx
movapd %xmm1, %xmm0
jmp 0x36e1
movq %r13, %rax
shlq $0x20, %rax
movl %edx, %ecx
orq %rax, %rcx
movq %rcx, 0x20(%rsp)
movsd %xmm0, 0x28(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x5032
incq %r13
jmp 0x36c4
leaq 0xa8(%rsp), %r12
leaq 0x20(%rsp), %r13
movq 0x50(%rsp), %rax
cmpq 0x58(%rsp), %rax
je 0x379d
movl (%rax), %r15d
movl 0x4(%rax), %ebp
leaq 0x50(%rsp), %rdi
callq 0x504c
movl %r15d, 0x20(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x591c
cmpq %r14, %rax
jne 0x373b
movl %r15d, 0x20(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x5fc2
movl %ebp, 0x20(%rsp)
leaq 0x78(%rsp), %rdi
movq %r13, %rsi
callq 0x5fc2
movslq %r15d, %rax
movq 0x10(%rsp), %rcx
movq (%rcx), %rcx
movl %ebp, (%rcx,%rax,4)
jmp 0x373b
xorl %eax, %eax
leaq 0x78(%rsp), %r15
leaq 0x20(%rsp), %r12
leaq 0xa8(%rsp), %r13
leaq 0xc(%rsp), %rbp
movl %eax, 0x20(%rsp)
cmpl 0x4(%rbx), %eax
jae 0x3886
movq %r15, %rdi
movq %r12, %rsi
callq 0x591c
leaq 0x80(%rsp), %rcx
cmpq %rcx, %rax
jne 0x387b
movl (%rbx), %eax
movl %eax, 0x8(%rsp)
xorl %ecx, %ecx
movsd 0x58c1(%rip), %xmm0     # 0x90b0
movsd %xmm0, 0x18(%rsp)
movl %ecx, 0xc(%rsp)
cmpl %eax, %ecx
jae 0x385b
movl %ecx, %eax
movq 0xb0(%rbx), %rdx
imulq $0x18, %rax, %rax
movl 0x20(%rsp), %esi
movq (%rdx,%rax), %rax
movsd 0x18(%rsp), %xmm0
ucomisd (%rax,%rsi,8), %xmm0
jbe 0x3855
movq %r13, %rdi
movq %rbp, %rsi
callq 0x591c
movl 0xc(%rsp), %ecx
cmpq %r14, %rax
jne 0x3855
movq 0xb0(%rbx), %rax
imulq $0x18, %rcx, %rdx
movl 0x20(%rsp), %esi
movq (%rax,%rdx), %rax
movsd (%rax,%rsi,8), %xmm0
movsd %xmm0, 0x18(%rsp)
movl %ecx, 0x8(%rsp)
incl %ecx
movl (%rbx), %eax
jmp 0x37f5
movl 0x20(%rsp), %eax
movl 0x8(%rsp), %ecx
movq 0x10(%rsp), %rdx
movq (%rdx), %rdx
movl %eax, (%rdx,%rcx,4)
movq %r13, %rdi
leaq 0x8(%rsp), %rsi
callq 0x596e
movl 0x20(%rsp), %eax
incl %eax
jmp 0x37b6
movq 0x10(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
leaq 0x20(%rsp), %rdi
callq 0x4fee
movl (%rbx), %eax
cmpq %rax, 0x48(%rsp)
jne 0x38e2
leaq 0x20(%rsp), %rdi
callq 0x523a
leaq 0x50(%rsp), %rdi
callq 0x5292
leaq 0x78(%rsp), %rdi
callq 0x523a
leaq 0xa8(%rsp), %rdi
callq 0x523a
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x584a(%rip), %rdi      # 0x9133
leaq 0x5807(%rip), %rsi      # 0x90f7
leaq 0x587d(%rip), %rcx      # 0x9174
movl $0xaa, %edx
callq 0x2150
jmp 0x3911
jmp 0x3911
jmp 0x3911
jmp 0x3911
jmp 0x3911
jmp 0x3911
jmp 0x3911
jmp 0x3911
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x5292
leaq 0x78(%rsp), %rdi
callq 0x523a
leaq 0xa8(%rsp), %rdi
callq 0x523a
movq %rbx, %rdi
callq 0x2390
nop