I'm working with dictionaries and the most problem that they are referenced to each other. I need to create a deep clone (smth like this it's named).
I use population as initial dictionary where I store graphs, then I need to take elements from Population, change them, write to childPopulation then some calculations and changed elements becomes in scores. Finnaly I need to merge population and scores dictionaries.
The problem is that when I change elements from population they changed there ofcause. I need some how to create a copy of population whil will be not referenced with initial.
population = new Dictionary<AdjacencyGraph<Figure, TaggedEdge<Figure, double>>, double>();
addElement(p1, initialGraph);
Run(initialGraph, p1);
double scoreBest = RMSECalc();
population.Add(initialGraph, scoreBest);
while (scoreBest >= 1.0)
{
childPopulation = new List<AdjacencyGraph<Figure, TaggedEdge<Figure, double>>>();
var parentList = new Dictionary<AdjacencyGraph<Figure, TaggedEdge<Figure, double>>, double>();
foreach (var parent in population)
{
childPopulation.Add(Mutate(parent.Key));
}
GetBestSolution(childPopulation);
scores = scores.OrderBy(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
if (scores.First().Value < scoreBest)
scoreBest = scores.First().Value;
scores.ToList().ForEach(x => population.Add(x.Key, x.Value));
population.Take(50);
scores = new Dictionary<AdjacencyGraph<Figure, TaggedEdge<Figure, double>>, double>();
childPopulation = new List<AdjacencyGraph<Figure, TaggedEdge<Figure, double>>>();
}