public void puzzle() { int movesCount = 0; Node emptyNode = null; foreach (var nodesList in nodes2DArray) { foreach (Node node in nodesList) { if (node.used == 0) { emptyNode = node; } } } findAccessibleNodes(emptyNode); selectedNode = nodes2DArray[rowIndex][0]; NodeSnapshot targetSnapshot = findShortestPathFromSelectedtoXY(0, 0); selectedNode = emptyNode; NodeSnapshot toRowIndexSnapshot = findShortestPathFromSelectedtoXY(targetSnapshot.path[0].x, targetSnapshot.path[0].y); selectedNode = toRowIndexSnapshot.path[toRowIndexSnapshot.path.Count - 2]; movesCount += toRowIndexSnapshot.path.Count - 2; for (int i = 1; i < targetSnapshot.path.Count; ++i) { Queue queue = new Queue(); queue.Enqueue(new NodeSnapshot(selectedNode)); List <NodeSnapshot> examinedNodes = new List <NodeSnapshot>(); movesCount++; while (queue.Count > 0) { NodeSnapshot examinedNodeSnapshot = (NodeSnapshot)queue.Dequeue(); Node examinedNode = examinedNodeSnapshot.node; if (examinedNode == targetSnapshot.path[i - 1]) { continue; } if (examinedNode == targetSnapshot.path[i]) { movesCount += examinedNodeSnapshot.path.Count - 1; selectedNode = targetSnapshot.path[i - 1]; break; } findPossibleMoves(examinedNode, examinedNodes, examinedNodeSnapshot.path, queue); } } Console.WriteLine("movesCount: " + movesCount + "\n"); }
private NodeSnapshot findShortestPathFromSelectedtoXY(int x, int y) { Queue queue = new Queue(); List <NodeSnapshot> examinedNodes = new List <NodeSnapshot>(); examinedNodes.Add(new NodeSnapshot(selectedNode)); queue.Enqueue(new NodeSnapshot(selectedNode)); while (queue.Count > 0) { NodeSnapshot examinedNodeSnapshot = (NodeSnapshot)queue.Dequeue(); Node examinedNode = examinedNodeSnapshot.node; if (examinedNode.x == x && examinedNode.y == y) { return(examinedNodeSnapshot); } findPossibleMoves(examinedNode, examinedNodes, examinedNodeSnapshot.path, queue); } return(null); }
public ProbeResult Execute <T>(T snapshot) { NodeSnapshot data = snapshot as NodeSnapshot; ProbeResult result; var probeData = new List <ProbeData> { new ProbeDataImpl("NetworkPartitions", data.NetworkPartitions.ToString()) }; if (data.NetworkPartitions.Any()) { _kb.TryGet(Metadata.Id, ProbeResultStatus.Unhealthy, out var article); result = new UnhealthyProbeResult(data.ClusterIdentifier, data.Identifier, Metadata.Id, Metadata.Name, ComponentType, probeData, article); } else { _kb.TryGet(Metadata.Id, ProbeResultStatus.Healthy, out var article); result = new HealthyProbeResult(data.ClusterIdentifier, data.Identifier, Metadata.Id, Metadata.Name, ComponentType, probeData, article); } NotifyObservers(result); return(result); }
public ProbeResult Execute <T>(T snapshot) { ProbeResult result; NodeSnapshot data = snapshot as NodeSnapshot; var probeData = new List <ProbeData> { new ProbeDataImpl("AvailableCoresDetected", data.AvailableCoresDetected.ToString()) }; if (data.AvailableCoresDetected <= 0) { _kb.TryGet(Metadata.Id, ProbeResultStatus.Unhealthy, out var article); result = new UnhealthyProbeResult(data.ClusterIdentifier, data.Identifier, Metadata.Id, Metadata.Name, ComponentType, probeData, article); } else { _kb.TryGet(Metadata.Id, ProbeResultStatus.Healthy, out var article); result = new HealthyProbeResult(data.ClusterIdentifier, data.Identifier, Metadata.Id, Metadata.Name, ComponentType, probeData, article); } NotifyObservers(result); return(result); }
public ProbeResult Execute <T>(T snapshot) { ProbeResult result; NodeSnapshot data = snapshot as NodeSnapshot; if (_config.IsNull() || _config.Probes.IsNull()) { _kb.TryGet(Metadata.Id, ProbeResultStatus.NA, out var article); result = new NotApplicableProbeResult(!data.IsNull() ? data.ClusterIdentifier : null, !data.IsNull() ? data.Identifier : null, Metadata.Id, Metadata.Name, ComponentType, article); NotifyObservers(result); return(result); } ulong warningThreshold = ComputeThreshold(data.OS.SocketDescriptors.Available); var probeData = new List <ProbeData> { new ProbeDataImpl("OS.Sockets.Available", data.OS.SocketDescriptors.Available.ToString()), new ProbeDataImpl("OS.Sockets.Used", data.OS.SocketDescriptors.Used.ToString()), new ProbeDataImpl("CalculatedThreshold", warningThreshold.ToString()) }; if (data.OS.SocketDescriptors.Used < warningThreshold && warningThreshold < data.OS.SocketDescriptors.Available) { _kb.TryGet(Metadata.Id, ProbeResultStatus.Healthy, out var article); result = new HealthyProbeResult(data.ClusterIdentifier, data.Identifier, Metadata.Id, Metadata.Name, ComponentType, probeData, article); } else if (data.OS.SocketDescriptors.Used == data.OS.SocketDescriptors.Available) { _kb.TryGet(Metadata.Id, ProbeResultStatus.Unhealthy, out var article); result = new UnhealthyProbeResult(data.ClusterIdentifier, data.Identifier, Metadata.Id, Metadata.Name, ComponentType, probeData, article); } else { _kb.TryGet(Metadata.Id, ProbeResultStatus.Warning, out var article); result = new WarningProbeResult(data.ClusterIdentifier, data.Identifier, Metadata.Id, Metadata.Name, ComponentType, probeData, article); } NotifyObservers(result); return(result); }