public static double GetMappingCost(Mapping mapping, Architecture architecture, LogicalCircuit circuit) { // Parameters to calculate the weight of each gate double p1 = circuit.NbCnotGates / Math.Min(circuit.NbGates, MAX_NB_GATES_IN_COST); double p2 = 0.1; double cost = 0; int NbOfGatesLookedAt = 0; for (int i = 0; i < circuit.NbCnotGates; i++) { double weight = 1 / (++NbOfGatesLookedAt / p1 + p2); if (circuit.Gates[i] is CNOT) { cost += architecture.GetCost(mapping.Map[((CNOT)circuit.Gates[i]).GetControlQubit()], mapping.Map[((CNOT)circuit.Gates[i]).GetTargetQubit()]); } if (NbOfGatesLookedAt > MAX_NB_GATES_IN_COST) { return(cost); } } return(cost); }