Ejemplo n.º 1
0
void apply_lnn( circuit& circ, const circuit& base, lnn_optimization_mode operation, gate::line allocation[])
{
    unsigned index = 0;
    foreach( const gate& g, base) {
        if(is_toffoli(g)) {
            //do nothing for this gate
        }
        else {
            gate_details gate_d= calculate_gate_details(g, operation, allocation, base);
            //std::cout << gate_d.distance << std::endl;
            if(gate_d.control_exists)
            {
                unsigned abs_dist = abs(gate_d.distance);
                if(abs_dist > 0)
                {
                    index+=abs_dist;
                    adding_swap_gates(circ, gate_d , index, operation, allocation);

                    if(operation == LNN_OPTIMIZATION_NAIVE)
                        index+=abs_dist;

                    //remove old gate
                    circ.remove_gate_at(index+1);
                }
                else {
                    if(operation == LNN_OPTIMIZATION_LOCAL_REORDER) {
                        circ.insert_gate(index) = gate_d.mod_gate;
                        circ.remove_gate_at(index+1);
                    }
                }
            }
            index++;
        }
    }
}