public void Load(GCPData data) { Encoding.Length = data.Nodes; AdjacencyListParameter.Value = new IntMatrix(data.Adjacencies); if (data.BestKnownColoring != null) { var colors = data.BestKnownColoring.Distinct().Count(); BestKnownColorsParameter.Value = new IntValue(colors); if (FitnessFunction == FitnessFunction.Prioritized) { var mag = Math.Pow(10, -(int)Math.Ceiling(Math.Log10(data.Nodes))); BestKnownQuality = colors * mag; } else { var nodesPerColor = data.BestKnownColoring.GroupBy(x => x).Select(x => x.Count()); BestKnownQuality = -nodesPerColor.Sum(x => x * x); } } else if (data.BestKnownColors.HasValue) { BestKnownColorsParameter.Value = new IntValue(data.BestKnownColors.Value); if (FitnessFunction == FitnessFunction.Prioritized) { var mag = Math.Pow(10, -(int)Math.Ceiling(Math.Log10(data.Nodes))); // the value is e.g. 0.051 for 0 conflicts with 51 colors (and less than 1000 nodes) BestKnownQuality = data.BestKnownColors.Value * mag; } else { BestKnownQualityParameter.Value = null; } } else { BestKnownColorsParameter.Value = null; BestKnownQualityParameter.Value = null; } Name = data.Name; Description = data.Description; OnReset(); }
public GCPData Export() { var instance = new GCPData(); instance.Name = Name; instance.Description = Description; instance.Nodes = Encoding.Length; var adjList = AdjacencyListParameter.Value; instance.Adjacencies = new int[adjList.Rows, 2]; for (var r = 0; r < adjList.Rows; r++) { instance.Adjacencies[r, 0] = adjList[r, 0]; instance.Adjacencies[r, 1] = adjList[r, 1]; } if (BestKnownColorsParameter.Value != null) { instance.BestKnownColors = BestKnownColorsParameter.Value.Value; } return(instance); }