/**
 * Create new leaf nodes by copying the children of <code>parent</code>
 * TODO: Should let parent be const, but setting its index property to be able to rebuild the edge structure.
 * Do that in a preparation step instead.
 */
void TreeData::readFromSubNetwork(NodeBase* parent)
{
	// Clone all nodes
	unsigned int numNodes = parent->childDegree();
	reserveNodeCount(numNodes);
	unsigned int i = 0;
	for (NodeBase::sibling_iterator childIt(parent->begin_child()), endIt(parent->end_child());
			childIt != endIt; ++childIt, ++i)
	{
		addNewNode(*childIt); // New node copies the data from the other
		childIt->index = i; // Set index to its place in this subnetwork to be able to find edge target below
	}

	// Clone edges
	for (NodeBase::sibling_iterator childIt(parent->begin_child()), endIt(parent->end_child());
			childIt != endIt; ++childIt)
	{
		NodeBase& node = *childIt;
		for (NodeBase::edge_iterator outEdgeIt(node.begin_outEdge()), endIt(node.end_outEdge());
				outEdgeIt != endIt; ++outEdgeIt)
		{
			EdgeType edge = **outEdgeIt;
			// If neighbour node is within the same cluster, add the link to this subnetwork.
			if (edge.target.parent == parent)
			{
				addEdge(node.index, edge.target.index, edge.data.weight, edge.data.flow);
			}
			// else flow out of sub-network
		}
	}
}
    void ParametersInterpreter<NMSmodelT>::setSubjectParameters(const std::vector<double>& x) {


        unsigned count = 0;
        for (typename ParametersMap::const_iterator it(parameters_.begin()); it != parameters_.end(); ++it) {

            unsigned noCoefficients = it->second.size;
            std::vector<double>::const_iterator startIt(x.begin() + count);
            std::vector<double>::const_iterator endIt(x.begin() + count + noCoefficients);
            std::vector<double> groupedCoefficients(startIt, endIt);
            std::vector<double> coefficients;

            getCoefficients(it->first, coefficients);
            distributeValues(it->second.muscleGroups, coefficients, groupedCoefficients);
            setCoefficients(it->first, coefficients);

            count += noCoefficients;

        }

    }