<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def add_replica(self, partition_name, count=1):
 """Adding a replica is done by trying to add the replica to every broker in the cluster and choosing the resulting state with the highest fitness score. :param partition_name: (topic_id, partition_id) of the partition to add replicas of. :param count: The number of replicas to add. """

        try:
            partition = self.cluster_topology.partitions[partition_name]
        except KeyError:
            raise InvalidPartitionError(
                "Partition name {name} not found.".format(name=partition_name),
            )

        active_brokers = self.cluster_topology.active_brokers

        if partition.replication_factor + count > len(active_brokers):
            raise InvalidReplicationFactorError(
                "Cannot increase replication factor from {rf} to {new_rf}."
                " There are only {brokers} active brokers."
                .format(
                    rf=partition.replication_factor,
                    new_rf=partition.replication_factor + count,
                    brokers=len(active_brokers),
                )
            )

        partition_index = self.state.partition_indices[partition]

        for _ in range(count):
            # Find eligible replication-groups.
            non_full_rgs = [
                rg for rg in six.itervalues(self.cluster_topology.rgs)
                if rg.count_replica(partition) < len(rg.active_brokers)
            ]
            # Since replicas can only be added to non-full rgs, only consider
            # replicas on those rgs when determining which rgs are
            # under-replicated.
            replica_count = sum(
                rg.count_replica(partition)
                for rg in non_full_rgs
            )
            opt_replicas, _ = compute_optimum(
                len(non_full_rgs),
                replica_count,
            )
            under_replicated_rgs = [
                rg for rg in non_full_rgs
                if rg.count_replica(partition) < opt_replicas
            ] or non_full_rgs

            # Add the replica to every eligible broker, as follower and leader
            new_states = []
            for rg in under_replicated_rgs:
                for broker in rg.active_brokers:
                    if broker not in partition.replicas:
                        broker_index = self.state.brokers.index(broker)
                        new_state = self.state.add_replica(
                            partition_index,
                            broker_index,
                        )
                        new_state_leader = new_state.move_leadership(
                            partition_index,
                            broker_index,
                        )
                        new_states.extend([new_state, new_state_leader])

            # Update cluster topology with highest scoring state.
            self.state = sorted(new_states, key=self._score, reverse=True)[0]
            self.cluster_topology.update_cluster_topology(self.state.pending_assignment)

            # Update the internal state to match.
            self.state.clear_pending_assignment()