private void Generate(uint stepCount, double probability, uint edges) { GenerateInitialGraph(probability); container = initialcontainer; while (stepCount > 0) { double[] probabilyArray = container.CountProbabilities(); container.AddVertex(); container.RefreshNeighbourships(MakeGenerationStep(probabilyArray, edges)); --stepCount; } }
public override Object Clone() { NonHierarchicContainer clone = (NonHierarchicContainer)this.MemberwiseClone(); clone.data = (BitArray[])this.data.Clone(); clone.degrees = new List <int>(this.degrees); if (evolutionInformation != null) { clone.evolutionInformation = (EdgesInformation)this.evolutionInformation.Clone(); } if (activeNodes != null) { clone.activeNodes = (BitArray)this.activeNodes.Clone(); } return(clone); }
/// <summary> /// Clones the container. /// </summary> /// <returns>Cloned container.</returns> public NonHierarchicContainer Clone() { NonHierarchicContainer clone = (NonHierarchicContainer)this.MemberwiseClone(); clone.neighbourship = new SortedDictionary <int, List <int> >(this.neighbourship); foreach (var item in this.neighbourship) { clone.neighbourship[item.Key] = new List <int>(item.Value); } clone.degrees = new List <int>(this.degrees); clone.existingEdges = new List <KeyValuePair <int, int> >(existingEdges); clone.nonExistingEdges = new List <KeyValuePair <int, int> >(nonExistingEdges); if (activeNodes != null) { clone.activeNodes = new BitArray(activeNodes); } return(clone); }
public NonHierarchicContainer Clone() { NonHierarchicContainer clone = (NonHierarchicContainer)this.MemberwiseClone(); clone.data = new BitArray[maxSize]; for (int i = 1; i < maxSize; i++) { clone.data[i] = new BitArray(i, false); } for (int i = 0; i < size; i++) { for (int j = i + 1; j < size; j++) { if (AreConnected(i, j)) { clone.AddConnection(i, j); } } } clone.degrees = new List <int>(this.degrees); return(clone); }
public BANetworkGenerator() { container = new NonHierarchicContainer(); initialcontainer = new NonHierarchicContainer(); }
public ConnectedComponents(NonHierarchicContainer component, Dictionary<int, int> vertexmatching, int count) { this.component = component; this.vertexmatching = vertexmatching; this.count = count; }
public ERNetworkGenerator() { container = new NonHierarchicContainer(); }
protected override SortedDictionary<UInt32, Double> CalculateCycles3Trajectory() { // Retrieving research parameters from network. // // TODO without parce if(network.ResearchParameterValues == null) throw new CoreException("Research parameters are not set."); UInt32 stepCount = UInt32.Parse(network.ResearchParameterValues[ResearchParameter.EvolutionStepCount].ToString()); Single nu = Single.Parse(network.ResearchParameterValues[ResearchParameter.Nu].ToString()); bool permanentDistribution = Boolean.Parse(network.ResearchParameterValues[ResearchParameter.PermanentDistribution].ToString()); object v = network.ResearchParameterValues[ResearchParameter.TracingStepIncrement]; UInt16 tracingStepIncrement = ((v != null) ? UInt16.Parse(v.ToString()) : (ushort)0); // keep initial container NonHierarchicContainer initialContainer = container.Clone(); SortedDictionary<UInt32, double> trajectory = new SortedDictionary<UInt32, double>(); uint currentStep = 0; uint currentTracingStep = tracingStepIncrement; double currentCycle3Count = CalculateCycles3(); trajectory.Add(currentStep, currentCycle3Count); NonHierarchicContainer previousContainer = new NonHierarchicContainer(); RNGCrypto rand = new RNGCrypto(); while (currentStep != stepCount) { previousContainer = container.Clone(); try { ++currentStep; long deltaCount = permanentDistribution ? container.PermanentRandomization() : container.NonPermanentRandomization(); double newCycle3Count = currentCycle3Count + deltaCount; int delta = (int)(newCycle3Count - currentCycle3Count); if (delta > 0) { // accept trajectory.Add(currentStep, newCycle3Count); currentCycle3Count = newCycle3Count; } else { double probability = Math.Exp((-nu * Math.Abs(delta))); if (rand.NextDouble() < probability) { // accept trajectory.Add(currentStep, newCycle3Count); currentCycle3Count = newCycle3Count; } else { // reject trajectory.Add(currentStep, currentCycle3Count); container = previousContainer; } } if (currentTracingStep == currentStep - 1) { container.Trace(network.ResearchName, "Realization_" + network.NetworkID.ToString(), "Matrix_" + currentTracingStep.ToString()); currentTracingStep += tracingStepIncrement; } } catch (Exception ex) { container = initialContainer; //log.Error(String.Format("Error occurred in step {0} ,Error message {1} ", currentStep, ex.InnerException)); } } container = initialContainer; return trajectory; }
public ConnectedComponents(NonHierarchicContainer component, Dictionary <int, int> vertexmatching, int count) { this.component = component; this.vertexmatching = vertexmatching; this.count = count; }
protected override SortedDictionary<Double, Double> CalculateCycles3Trajectory() { // Retrieving research parameters from network. Research MUST be Evolution. // Debug.Assert(network.ResearchParameterValues != null); Debug.Assert(network.ResearchParameterValues.ContainsKey(ResearchParameter.EvolutionStepCount)); Debug.Assert(network.ResearchParameterValues.ContainsKey(ResearchParameter.TracingStepIncrement)); Debug.Assert(network.ResearchParameterValues.ContainsKey(ResearchParameter.Nu)); Debug.Assert(network.ResearchParameterValues.ContainsKey(ResearchParameter.PermanentDistribution)); UInt32 stepCount = Convert.ToUInt32(network.ResearchParameterValues[ResearchParameter.EvolutionStepCount]); Double nu = Convert.ToDouble(network.ResearchParameterValues[ResearchParameter.Nu]); bool permanentDistribution = Convert.ToBoolean(network.ResearchParameterValues[ResearchParameter.PermanentDistribution]); object v = network.ResearchParameterValues[ResearchParameter.TracingStepIncrement]; UInt32 tracingStepIncrement = ((v != null) ? Convert.ToUInt32(v) : 0); // keep initial container NonHierarchicContainer initialContainer = container.Clone(); SortedDictionary<Double, Double> trajectory = new SortedDictionary<Double, Double>(); uint currentStep = 0; uint currentTracingStep = tracingStepIncrement; double currentCycle3Count = CalculateCycles3(); trajectory.Add(currentStep, currentCycle3Count); NonHierarchicContainer previousContainer = new NonHierarchicContainer(); RNGCrypto rand = new RNGCrypto(); while (currentStep != stepCount) { previousContainer = container.Clone(); try { ++currentStep; long deltaCount = permanentDistribution ? container.PermanentRandomization() : container.NonPermanentRandomization(); double newCycle3Count = currentCycle3Count + deltaCount; int delta = (int)(newCycle3Count - currentCycle3Count); if (delta > 0) { // accept trajectory.Add(currentStep, newCycle3Count); currentCycle3Count = newCycle3Count; } else { double probability = Math.Exp((-nu * Math.Abs(delta))); if (rand.NextDouble() < probability) { // accept trajectory.Add(currentStep, newCycle3Count); currentCycle3Count = newCycle3Count; } else { // reject trajectory.Add(currentStep, currentCycle3Count); container = previousContainer; } } network.UpdateStatus(NetworkStatus.StepCompleted); if (currentTracingStep == currentStep) { container.Trace(network.ResearchName, "Realization_" + network.NetworkID.ToString(), "Matrix_" + currentTracingStep.ToString()); currentTracingStep += tracingStepIncrement; network.UpdateStatus(NetworkStatus.StepCompleted); } } catch (SystemException) { container = initialContainer; } } container = initialContainer; return trajectory; }
public ConnectedComponents GetSubGraph(IEnumerable<int> nodes) { ConnectedComponents comp; NonHierarchicContainer g = new NonHierarchicContainer(); Dictionary<int, int> tempnodes = new Dictionary<int, int>(); for (int i = 0; i < nodes.Count(); i++) { tempnodes = AddNodesToList(nodes); g.AddVertex(); } foreach (var n in g.Neighbourship.Keys.ToList()) { foreach (var neigh in container.Neighbourship[tempnodes[n]]) { for (int i = 0; i < tempnodes.Count; i++) { if (tempnodes[i] == neigh) { g.AddConnection(n, i); } } } } comp = new ConnectedComponents(g, tempnodes, tempnodes.Count); return comp; }