// File: /workspace/github_cpp_makefile_star2_O2/mapequation[P]partition-validation/./partition-validation.h
// Function: Partitions::readPartitionsFile()
void Partitions::readPartitionsFile() {
    cout << "Reading partitions file " << flush;

    string line;
    string buf;

    // Count number of nodes and boot partitions
    getline(ifs, line);
    nNodes++; // First line corresponds to first node

    {
        istringstream read(line);
        while (read >> buf) nPartitions++;
    }

    if (crossValidateK > 0) {
        nValidationPartitions = nPartitions / crossValidateK;
    }

    if (nTrainingPartitions == 0) {
        if (nPartitions - nValidationPartitions > 0) {
            nTrainingPartitions = nPartitions - nValidationPartitions;
        } else {
            cout << "-- Not enough partitions for validation. Will not validate." << endl;
        }
    } else if (nPartitions - nValidationPartitions - nTrainingPartitions < 0) {
        cout << "-- Not enough partitions for training and validation." << endl;
    }

    cout << "with " << nPartitions << " partitions..." << flush;

    // Count remaining nodes
    while (getline(ifs, line)) {
        nNodes++;
    }

    if (ifs.bad()) {
        cout << "Error while reading file" << endl;
    }

    cout << "of " << nNodes << " nodes..." << flush;

    partitions = vector<Partition>(nPartitions);

    for (int i = 0; i < nPartitions; i++) {
        partitions[i] = Partition(i, nNodes);
    }

    // Restart from beginning of file
    vector<map<string, int> > partitionsAssignmentId(nPartitions);
    vector<int> partitionsAssignmentIds(nPartitions, 0);
    ifs.clear();
    ifs.seekg(0, ios::beg);

    // Read partitions data
    int nodeNr = 0;

    while (getline(ifs, line)) {
        istringstream read(line);
        int i = 0;

        while (read >> buf) {
            vector<string> assignments = tokenize(buf, ':');
            string assignmentKey;

            for (auto &assignment: assignments) {
                assignmentKey += assignment + ":";

                auto lookup = partitionsAssignmentId[i].find(assignmentKey);
                int assignmentId = partitionsAssignmentIds[i];

                if (lookup != end(partitionsAssignmentId[i])) {
                    assignmentId = lookup->second;
                } else {
                    partitionsAssignmentId[i][assignmentKey] = partitionsAssignmentIds[i];
                    partitionsAssignmentIds[i]++;
                }

                partitions[i].assignments[nodeNr].push_back(assignmentId);
                partitions[i].clusterSizes[assignmentId]++;
            }
            i++;
        }
        nodeNr++;
    }

    cout << "done!" << endl;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x278, %rsp            # imm = 0x278
movq %rdi, %r14
movq 0xa00b(%rip), %rdi      # 0xdfd8
leaq 0x50f5(%rip), %rsi      # 0x90c9
callq 0x3240
movq %rax, %rdi
callq 0x3190
leaq 0x60(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
leaq 0xc8(%rsp), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
xorl %edx, %edx
movb %dl, (%rax)
movb %dl, (%rcx)
leaq 0xb0(%r14), %r12
leaq 0x50(%rsp), %rsi
movq %r12, %rdi
callq 0x3060
incl 0x4d8(%r14)
leaq 0xf8(%rsp), %rdi
leaq 0x50(%rsp), %rsi
pushq $0x8
popq %rdx
callq 0x33b0
leaq 0xf8(%rsp), %rbx
leaq 0xb8(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x32d0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x4068
incl 0x4dc(%r14)
jmp 0x4046
leaq 0xf8(%rsp), %rdi
callq 0x3120
movl 0x68(%r14), %ecx
testl %ecx, %ecx
jle 0x408e
movl 0x4dc(%r14), %eax
cltd
idivl %ecx
movl %eax, 0x4e8(%r14)
movl 0x4dc(%r14), %eax
movl 0x4e4(%r14), %ecx
movl 0x4e8(%r14), %edx
testl %ecx, %ecx
je 0x40b6
addl %edx, %ecx
cmpl %ecx, %eax
jns 0x40de
leaq 0x506a(%rip), %rsi      # 0x911e
jmp 0x40ca
subl %edx, %eax
jle 0x40c3
movl %eax, 0x4e4(%r14)
jmp 0x40de
leaq 0x5018(%rip), %rsi      # 0x90e2
movq 0x9f07(%rip), %rdi      # 0xdfd8
callq 0x3240
movq %rax, %rdi
callq 0x3130
movq 0x9ef3(%rip), %rdi      # 0xdfd8
leaq 0x5068(%rip), %rsi      # 0x9154
callq 0x3240
movl 0x4dc(%r14), %esi
movq %rax, %rdi
callq 0x33d0
leaq 0x5053(%rip), %rsi      # 0x915a
movq %rax, %rdi
callq 0x3240
movq %rax, %rdi
callq 0x3190
leaq 0x50(%rsp), %rbx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x3060
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x413e
incl 0x4d8(%r14)
jmp 0x411c
movq (%r12), %rax
movq -0x18(%rax), %rax
testb $0x1, 0x20(%r12,%rax)
je 0x4169
movq 0x9e83(%rip), %rdi      # 0xdfd8
leaq 0x500d(%rip), %rsi      # 0x9169
callq 0x3240
movq %rax, %rdi
callq 0x3130
movq 0x9e68(%rip), %rdi      # 0xdfd8
leaq 0x4f10(%rip), %rsi      # 0x9087
callq 0x3240
movl 0x4d8(%r14), %esi
movq %rax, %rdi
callq 0x33d0
leaq 0x4ff0(%rip), %rsi      # 0x9182
movq %rax, %rdi
callq 0x3240
movq %rax, %rdi
callq 0x3190
movq %r12, 0x10(%rsp)
movslq 0x4dc(%r14), %rsi
leaq 0xf8(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x58e0
leaq 0x50(%r14), %rdi
leaq 0xf8(%rsp), %rbx
movq %rdi, 0x8(%rsp)
movq %rbx, %rsi
callq 0x7f86
movq %rbx, %rdi
callq 0x5932
xorl %r15d, %r15d
xorl %r12d, %r12d
movslq 0x4dc(%r14), %rsi
cmpq %rsi, %r12
jge 0x4229
movl 0x4d8(%r14), %edx
movq %rbx, %rdi
movl %r12d, %esi
callq 0x5954
movq 0x8(%rsp), %rax
movq (%rax), %rdi
addq %r15, %rdi
movq %rbx, %rsi
callq 0x59e2
movq %rbx, %rdi
callq 0x5a18
incq %r12
addq $0x58, %r15
jmp 0x41e7
leaq 0xa0(%rsp), %rdi
leaq 0xf8(%rsp), %rdx
callq 0x5a32
movslq 0x4dc(%r14), %rsi
leaq 0xf8(%rsp), %rdx
andl $0x0, (%rdx)
leaq 0x88(%rsp), %rdi
leaq 0x30(%rsp), %rcx
callq 0x5808
movq 0x10(%rsp), %rbx
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
xorl %esi, %esi
callq 0x33c0
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3310
movq $0x0, 0x18(%rsp)
leaq 0x30(%rsp), %rbx
leaq 0xd8(%rsp), %r12
movq 0x10(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x3060
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x4457
leaq 0xf8(%rsp), %rdi
leaq 0x50(%rsp), %rsi
pushq $0x8
popq %rdx
callq 0x33b0
imulq $0x18, 0x18(%rsp), %rax
movq %rax, 0x20(%rsp)
movq $0x0, (%rsp)
leaq 0xf8(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x32d0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x4440
leaq 0x70(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
pushq $0x3a
popq %rdx
callq 0x356c
leaq 0x40(%rsp), %rax
movq %rax, 0x30(%rsp)
andq $0x0, 0x38(%rsp)
movb $0x0, 0x40(%rsp)
movq 0x70(%rsp), %rbp
movq 0x78(%rsp), %rax
movq %rax, 0x28(%rsp)
movq (%rsp), %rax
imulq $0x30, %rax, %r13
imulq $0x58, %rax, %r15
cmpq 0x28(%rsp), %rbp
je 0x4425
movq %r12, %rdi
movq %rbp, %rsi
leaq 0x5453(%rip), %rdx      # 0x97ba
callq 0x5a83
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3410
movq %r12, %rdi
callq 0x3110
movq 0xa0(%rsp), %rdi
addq %r13, %rdi
movq %rbx, %rsi
callq 0x816e
movq 0x88(%rsp), %rcx
movq (%rsp), %rdx
movl (%rcx,%rdx,4), %r14d
movl %r14d, 0xd8(%rsp)
movq 0xa0(%rsp), %rdi
leaq (%rdi,%r13), %rcx
addq $0x8, %rcx
cmpq %rcx, %rax
je 0x43cb
movl 0x40(%rax), %eax
movl %eax, 0xd8(%rsp)
jmp 0x43e8
addq %r13, %rdi
movq %rbx, %rsi
callq 0x5abc
movl %r14d, (%rax)
movq 0x88(%rsp), %rax
movq (%rsp), %rcx
incl (%rax,%rcx,4)
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq 0x8(%rax,%r15), %rdi
addq 0x20(%rsp), %rdi
movq %r12, %rsi
callq 0x5b22
movq 0x8(%rsp), %rax
movq (%rax), %rax
leaq (%rax,%r15), %rdi
addq $0x20, %rdi
movq %r12, %rsi
callq 0x72e8
incl (%rax)
addq $0x20, %rbp
jmp 0x434f
incq (%rsp)
movq %rbx, %rdi
callq 0x3110
leaq 0x70(%rsp), %rdi
callq 0x5594
jmp 0x42e3
incq 0x18(%rsp)
leaq 0xf8(%rsp), %rdi
callq 0x3120
jmp 0x429a
movq 0x9b7a(%rip), %rdi      # 0xdfd8
leaq 0x4d27(%rip), %rsi      # 0x918c
callq 0x3240
movq %rax, %rdi
callq 0x3130
leaq 0x88(%rsp), %rdi
callq 0x7de4
leaq 0xa0(%rsp), %rdi
callq 0x5b40
leaq 0xb8(%rsp), %rdi
callq 0x3110
leaq 0x50(%rsp), %rdi
callq 0x3110
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x4534
jmp 0x44cf
jmp 0x44cf
jmp 0x44cf
jmp 0x44c8
jmp 0x44c8
jmp 0x44cf
jmp 0x44c8
movq %rax, %rbx
jmp 0x4527
jmp 0x44cf
movq %rax, %rbx
jmp 0x4541
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
callq 0x3120
jmp 0x4541
jmp 0x44e8
movq %rax, %rbx
jmp 0x451a
jmp 0x4503
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
callq 0x3110
jmp 0x4506
jmp 0x4503
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x3110
leaq 0x70(%rsp), %rdi
callq 0x5594
leaq 0xf8(%rsp), %rdi
callq 0x3120
leaq 0x88(%rsp), %rdi
callq 0x7de4
leaq 0xa0(%rsp), %rdi
callq 0x5b40
leaq 0xb8(%rsp), %rdi
callq 0x3110
leaq 0x50(%rsp), %rdi
callq 0x3110
movq %rbx, %rdi
callq 0x33e0