private void attack_Click(object sender, EventArgs e) { // 先判断这个图是否已经完全不连通 if (!(GraphUtils.getMaxDegree(this.currentData) == 0)) { // 先获取当前图的度最大的节点 int indexOfMaxDegree = GraphUtils.getIndexOfMaxDegree(this.currentData); // 然后把这个点删除 GraphUtils.removeNode(this.currentData, indexOfMaxDegree); this.attackedIndex.Add(indexOfMaxDegree); this.currentBm = new Bitmap(this.currentPic.Width, this.currentPic.Height); this.currentGra = Graphics.FromImage(this.currentBm); this.currentGra.Clear(Color.White); // 画圈 paintNode(this.currentPoint, this.currentGra, this.attackedIndex); // 画线 paintEdge(this.currentData, this.currentPoint, this.currentGra); // 写字 paintNodesName(this.currentPoint, this.currentGra, this.attackedIndex); this.currentPic.Image = this.currentBm; //将被攻击点写在被攻击序列 this.currentBm = new Bitmap(this.attackedIndexPic.Width, this.attackedIndexPic.Height); this.currentGra = Graphics.FromImage(this.currentBm); this.currentGra.Clear(Color.White); float x = 282; float y = 49; for (int i = 0; i < this.attackedIndex.Count; i++) { this.currentGra.DrawString((attackedIndex[i]).ToString(), this.attackedFont, this.attackedBrush, 2 + i * 18, 10); } this.attackedIndexPic.Image = this.currentBm; } }
public static void PrintOneSidedComp(IGraphBasics <Point, IEdgeBasics <Point> > CurrentGraph) { foreach (IEnumerable <Point> collP in GraphUtils.GetCollectionPointsOneSidedCompOfGraph(CurrentGraph)) { Console.WriteLine("Graph: {{{0}}}", String.Join(",", collP)); } }
/// <inheritdoc /> internal override async Task <List <CalendarSkillTimeSlotModel> > CallGraphServiceWithResultAsync(IGraphServiceClient client, IReadOnlyDictionary <string, object> parameters, CancellationToken cancellationToken) { var attendees = (List <Attendee>)parameters["Attendees"]; var duration = (int)parameters["Duration"]; var timeZone = GraphUtils.ConvertTimeZoneFormat((string)parameters["Timezone"]); MeetingTimeSuggestionsResult meetingTimesResult = await client.Me .FindMeetingTimes(attendees : attendees, minimumAttendeePercentage : 100, meetingDuration : new Duration(new TimeSpan(0, duration, 0)), maxCandidates : 10) .Request() .PostAsync(cancellationToken) .ConfigureAwait(false); var results = new List <CalendarSkillTimeSlotModel>(); foreach (var timeSlot in meetingTimesResult.MeetingTimeSuggestions) { if (timeSlot.Confidence >= 1) { var start = DateTime.Parse(timeSlot.MeetingTimeSlot.Start.DateTime); var end = DateTime.Parse(timeSlot.MeetingTimeSlot.End.DateTime); results.Add(new CalendarSkillTimeSlotModel() { Start = TimeZoneInfo.ConvertTimeFromUtc(start, timeZone), End = TimeZoneInfo.ConvertTimeFromUtc(end, timeZone), }); } } return(results.OrderBy(s => s.Start).ToList()); }
private void OpenGraph(Graph graph, bool closeCurrentlyOpenedGraph, bool clearGraphTabs, bool centerAllNodesInWindow, bool recordUndo = true) { if (graph == null) { return; } if (CurrentGraph == graph) { return; } if (closeCurrentlyOpenedGraph) { CloseCurrentGraph(clearGraphTabs); } if (recordUndo) { RecordUndo("Open Graph"); } WindowSettings.AddGraphToRecentlyOpenedGraphs(graph); CurrentGraph = graph; GraphUtils.CheckAndCreateAnyMissingSystemNodes(graph); ConstructGraphGUI(); if (centerAllNodesInWindow) { CenterAllNodesInWindow(); } // Undo.IncrementCurrentGroup(); // Undo.SetCurrentGroupName(m_graphAssetName); SetView(View.Graph); Repaint(); GraphEvent.Send(GraphEvent.EventType.EVENT_GRAPH_OPENED); m_graphAssetPath = AssetDatabase.GetAssetPath(CurrentGraph); }
private Bitmap2 CreateOverviewBitmap(int overviewWidth, int overviewHeight) { BitmapGraphics bg = new BitmapGraphics(Math.Min(main.TotalWidth(), 15000), Math.Min(main.TotalHeight(), 15000)); main.OnPaintMainView?.Invoke(bg, 0, 0, main.TotalWidth(), main.TotalHeight(), true); return(GraphUtils.ToBitmap2(GraphUtils.ResizeImage(bg.Bitmap, overviewWidth, overviewHeight))); }
private void calNodeCoefficient_Click(object sender, EventArgs e) { int index = (int)this.selectCoefficientNode.SelectedItem; double clusterCoefficient = GraphUtils.getClusterCoefficient(this.data, index); this.clusterCoefficient.Text = clusterCoefficient.ToString(); }
public void GraphUtilsShouldCalculateDijkstraReachWeightNonUniqueEdges() { #region Arrange var n = 4; List <Tuple <int, int> >[] edges = new List <Tuple <int, int> > [4]; edges[0] = new List <Tuple <int, int> >(); edges[0].Add(new Tuple <int, int>(1, 24)); edges[0].Add(new Tuple <int, int>(3, 20)); edges[0].Add(new Tuple <int, int>(3, 29)); edges[0].Add(new Tuple <int, int>(2, 3)); edges[1] = new List <Tuple <int, int> >(); edges[1].Add(new Tuple <int, int>(0, 24)); edges[2] = new List <Tuple <int, int> >(); edges[2].Add(new Tuple <int, int>(0, 3)); edges[2].Add(new Tuple <int, int>(3, 12)); edges[3] = new List <Tuple <int, int> >(); edges[3].Add(new Tuple <int, int>(2, 12)); edges[3].Add(new Tuple <int, int>(0, 29)); edges[3].Add(new Tuple <int, int>(0, 20)); #endregion #region Act var reach = GraphUtils.DijkstraReachWeight(n, edges, 0); #endregion #region Assert Assert.AreEqual(24, reach[1]); Assert.AreEqual(3, reach[2]); Assert.AreEqual(15, reach[3]); #endregion }
public void GraphUtilsShouldCalculateDijkstraReachWeight() { #region Arrange var n = 4; Dictionary <int, int>[] edges = new Dictionary <int, int> [4]; edges[0] = new Dictionary <int, int>(); edges[0].Add(1, 24); edges[0].Add(3, 20); edges[0].Add(2, 3); edges[1] = new Dictionary <int, int>(); edges[1].Add(0, 24); edges[2] = new Dictionary <int, int>(); edges[2].Add(0, 3); edges[2].Add(3, 12); edges[3] = new Dictionary <int, int>(); edges[3].Add(2, 12); edges[3].Add(0, 20); #endregion #region Act var reach = GraphUtils.DijkstraReachWeight(n, edges, 0); #endregion #region Assert Assert.AreEqual(24, reach[1]); Assert.AreEqual(3, reach[2]); Assert.AreEqual(15, reach[3]); #endregion }
public void GraphUtilsShouldCalculateKruskal() { #region Arrange var numNodes = 3; var edges = new GraphEdge[4]; edges[0].Node1 = 0; edges[0].Node1 = 1; edges[0].Weight = 3; edges[1].Node1 = 1; edges[1].Node1 = 2; edges[1].Weight = 2; edges[2].Node1 = 0; edges[2].Node1 = 2; edges[2].Weight = 1; edges[3].Node1 = 0; edges[3].Node1 = 1; edges[3].Weight = 2; #endregion #region Act Array.Sort(edges, new GraphEdgeWeightComparer()); var mst = GraphUtils.CalcKruskal(numNodes, edges); #endregion #region Assert Assert.AreEqual(3, mst.Select(index => edges[index]).Sum(e => e.Weight)); #endregion }
private void calNodeDegree_Click(object sender, EventArgs e) { int index = (int)this.selectDegreeNode.SelectedItem; int degree = GraphUtils.getDegreeeOfNode(this.data, index); this.nodeDegree.Text = degree.ToString(); }
public MainWindow() { InitializeComponent(); this.DataContext = this; CurrentNotation = new HtmlAdjacencyMatrixNotation(); TaskText = "8 вариант\nНайти количество дуг, инцидентных вершине графа G1 * G2, номер которой вводится с клавиатуры."; G1_Name = "G1"; G1_Points = 4; G1_Edges = 7; G2_Name = "G2"; G2_Points = 4; G2_Edges = 7; GraphG1 = GraphUtils.GenerateRandomDirectedGraph(G1_Name, G1_Points, G1_Edges); GraphG2 = GraphUtils.GenerateRandomDirectedGraph(G2_Name, G2_Points, G2_Edges); GraphGOut = GraphUtils.DirectedGraphIntersection(GraphG1, GraphG2); ListPointsGrapchOut = new ObservableCollection <DiscreteMaC_Lib.Graphes.Points.Point>(GraphGOut.PointCollection); HtmlDataG1 = CurrentNotation.ConvertFromGrapch(GraphG1); HtmlDataG2 = CurrentNotation.ConvertFromGrapch(GraphG2); HtmlDataGOut = CurrentNotation.ConvertFromGrapch(GraphGOut); }
/// <summary> /// Updates the preview texture for this editor. /// </summary> /// <param name="regenerateShader"> /// If true, regenerates the graph's shader, which takes a lot longer. /// This should be true whenever the graph itself changes. /// </param> private void UpdatePreview(bool regenerateShader = true) { //Update params. var oldParams = graphParams; graphParams = new GPUGraph.GraphParamCollection(graph); graphParams.SetParams(oldParams); //Create shader. if (regenerateShader || cachedPreviewMat == null) { string shaderText = graph.GenerateShader("Graph editor temp shader", "rgb", 1.0f); Shader shader = ShaderUtil.CreateShaderAsset(shaderText); if (shader == null) { Debug.LogError("Shader: " + shaderText); } else { cachedPreviewMat = new Material(shader); } } //Create texture. if (previewNoise == null) { previewNoise = new Texture2D(256, 256, TextureFormat.RGBA32, false); } //Set params and generate. graphParams.SetParams(cachedPreviewMat); cachedPreviewMat.SetFloat(GraphUtils.Param_UVz, uvZ); GraphUtils.GenerateToTexture(cachedPreviewMat, previewNoise, true); }
/// <summary> /// Delegate to find a game object by its tag /// </summary> /// <param name="tag">tag</param> /// <returns>corresponding game object</returns> static GameObject FindGameObjectWithTag(string tag) { if (tag == "Start") { switch (currentSize) { case GraphSize.Small: return(GraphUtils.GetStartWaypoint(GraphSize.Small).gameObject); case GraphSize.Medium: return(GraphUtils.GetStartWaypoint(GraphSize.Medium).gameObject); case GraphSize.Large: return(GraphUtils.GetStartWaypoint(GraphSize.Large).gameObject); } } else if (tag == "End") { switch (currentSize) { case GraphSize.Small: return(GraphUtils.GetEndWaypoint(GraphSize.Small).gameObject); case GraphSize.Medium: return(GraphUtils.GetEndWaypoint(GraphSize.Medium).gameObject); case GraphSize.Large: return(GraphUtils.GetEndWaypoint(GraphSize.Large).gameObject); } } // should never get here return(null); }
/// <summary> /// Gets the Min, Mean, or Max value from a specific EPA on the EPA Attaintment graph popup after the /// View More Reports link is clicked /// </summary> /// <param name="chrt">The chart element</param> /// <param name="epaName">The exact text from the EPA name on the graph. For example, if you have 6 observations completed for EPA 1.1, then the exact text would be "EPA 1.1 (6)"</param> /// <param name="meanMinOrMax">Either "min", "max" or "mean"</param> /// <returns></returns> public decimal GetMinMeanOrMaxFromEPAAttainGraph(IWebElement chrt, string epaName, string meanMinOrMax) { string columnToReturn = ""; DataTable EPAAttainGraphDT = GraphUtils.GetHighChartDataTable(Browser, chrt); if (meanMinOrMax == "mean") { columnToReturn = "average"; } if (meanMinOrMax == "min") { columnToReturn = "range0"; } if (meanMinOrMax == "max") { columnToReturn = "range1"; } string EPAObservationCount = DataUtils.GetDataTableCellByRecNameAndColName(EPAAttainGraphDT, "category", epaName, columnToReturn); // We need to round to the nearest whole number for min and max because DEV intentionally subtracts .05 for either value // because if not, the blue bar wouldnt show if (meanMinOrMax == "min" || meanMinOrMax == "max") { return(Math.Round(System.Convert.ToDecimal(EPAObservationCount))); } else { return(System.Convert.ToDecimal(EPAObservationCount)); } }
/// <summary> /// Create a target EQ from raw frequency responses, by averaging and smoothing the channels. /// </summary> static Equalizer MakeCurve(float[][] sourceFrequencyResponses, int sampleRate) { float[] target = new float[sourceFrequencyResponses[0].Length]; for (int i = 0; i < sourceFrequencyResponses.Length; ++i) { for (int sample = 0; sample < sourceFrequencyResponses[i].Length; ++sample) { target[sample] += sourceFrequencyResponses[i][sample]; } } float gain = 1 / (float)sourceFrequencyResponses.Length; for (int sample = 0; sample < target.Length; ++sample) { target[sample] *= gain; } const float startFreq = 20, endFreq = 20000, smoothness = .75f; const int resultSize = 1000; target = GraphUtils.ConvertToGraph(target, startFreq, endFreq, sampleRate, resultSize); target = GraphUtils.SmoothGraph(target, startFreq, endFreq, smoothness); GraphUtils.ConvertToDecibels(target); GraphUtils.Normalize(target); return(EQGenerator.FromGraph(target, startFreq, endFreq)); }
private void InitMainGraphTableColumn(ColumnMetadata mainTableColumn) { if (mainTableColumn.IsList) { GetInternalInstances(mainTableColumn, isList: true); } else if (typeof(IBaseModel).IsAssignableFrom(mainTableColumn.Type) || _dbMetadata.GetTableMetadatas().Any(x => x.Type == mainTableColumn.Type)) { GetInternalInstances(mainTableColumn); } else { if (Utilities.TypeExtensions.IsNumber(mainTableColumn.Type)) { Field( GraphUtils.ResolveGraphType(mainTableColumn.Type), mainTableColumn.ColumnName ); } FillArgs(mainTableColumn.ColumnName, mainTableColumn.Type); if (mainTableColumn.Type.IsEnum) { FillArgs($"{mainTableColumn.ColumnName}_enum", typeof(int)); } } }
/// <summary> /// Gets the current observation count from the EPA Observation Count graph /// </summary> /// <param name="chrt">The chart element</param> /// <param name="epaName"></param> /// <returns></returns> public int GetEPAObsvCntFromEPAObsGraph(IWebElement chrt, string epaName) { DataTable EPAObvCountGraphDT = GraphUtils.GetHighChartDataTable(Browser, chrt); string EPAObservationCount = DataUtils.GetDataTableCellByRecNameAndColName(EPAObvCountGraphDT, "category", epaName, "data"); return(Int32.Parse(EPAObservationCount)); }
public static void PrintTestRandomDirectedGraphWithValuedEdgeAndPointID() { DirectedGraphWithValuedEdgeAndPointID testGraph = GraphUtils.GenerateRandomDirectedGraphWithValuedEdgeAndPointID("G1", "x", 5); TextAdjacencyValueedMatrixNotation testNotation = new TextAdjacencyValueedMatrixNotation(); Console.WriteLine(testNotation.ConvertFromGrapch(testGraph)); }
// Update is called once per frame void OnRenderObject() { if (renderTime == DrawTime.OnRenderObject) { GraphUtils.DrawPendingLines(); } }
protected override void ProcessInternal(IGraph graph) { for (int i = 0; i < Vertexes; i++) { GraphUtils.GetDegree(graph, i); } }
public void CreateGraphTest() { var g = GraphUtils.GenerateSampleUndirectedGraph(); g.PrintAllVertices(); g.PrintAllEdges(); }
private void disPlayDegreeDistribution_Click(object sender, EventArgs e) { List <int> allDegree = GraphUtils.getAllDegree(this.data); complexNK.DegreeDistribution degreeDistributionForm = new complexNK.DegreeDistribution(CalDegreeNum(allDegree)); degreeDistributionForm.ShowDialog(); }
private void ConnectSockets(Socket outputSocket, Socket inputSocket, bool recordUndo = true, bool saveAssets = false) { if (recordUndo) { RecordUndo(GraphAction.Connect.ToString()); } GraphUtils.ConnectSockets(CurrentGraph, outputSocket, inputSocket, saveAssets); }
private void calNodeCoreness_Click(object sender, EventArgs e) { // 这里的index仍然是标号,并非list中的index int index = (int)this.selectCorenessNode.SelectedItem; List <int> allCoreness = GraphUtils.getNodeCoreness(this.data); this.nodeCoreness.Text = allCoreness[index - 1].ToString(); }
private void BtnGraphGOutRebuild_Click(object sender, RoutedEventArgs e) { GraphGOut = GraphUtils.DirectedGraphIntersection(GraphG1, GraphG2); ListPointsGrapchOut = new ObservableCollection <DiscreteMaC_Lib.Graphes.Points.Point>(GraphGOut.PointCollection); HtmlDataGOut = CurrentNotation.ConvertFromGrapch(GraphGOut); }
public static void TestSearchPathInGraph() { TestGraph1 = GraphUtils.GenerateRandomDirectedGraph("g1", 4, 10); Console.WriteLine(notation.ConvertFromGrapch(TestGraph1)); Console.WriteLine("==="); PrintAllEdgesForGraph(TestGraph1); }
public async Task <IActionResult> DownloadGraph([FromQuery] Uri graph) { var stream = await _graphService.DownloadGraph(graph); var file = File(stream, _mimetypeOctetStream, GraphUtils.GetFileName(graph)); return(file); }
private void randomAttack_Click(object sender, EventArgs e) { int index = (int)this.selectRandomAttackNode.SelectedItem; // 这里返回的是this.data的副本 List <List <string> > afterAttackData = GraphUtils.RandomAttack(this.data, index); complexNK.RandomAttack randomAttackForm = new complexNK.RandomAttack(this.data, afterAttackData, index); randomAttackForm.ShowDialog(); }
public void TestMonospaceFont() { var font2 = new Font2("Courier New", 9); var convertedFont = GraphUtils.ToFont(font2); var nativeFont = new Font(FontFamily.GenericMonospace, 9); Assert.AreEqual(nativeFont.Name, convertedFont.Name); Assert.AreEqual(nativeFont.Size, convertedFont.Size); }
private void RandomAttack_Load(object sender, EventArgs e) { // 初始化画板 this.beforeAttackBm = new Bitmap(this.beforeAttackPic.Width, this.beforeAttackPic.Height); this.beforeAttackGra = Graphics.FromImage(beforeAttackBm); this.beforeAttackGra.Clear(Color.White); this.afterAttackBm = new Bitmap(this.afterAttackPic.Width, this.afterAttackPic.Height); this.afterAttackGra = Graphics.FromImage(afterAttackBm); this.afterAttackGra.Clear(Color.White); // 初始化笔 this.circlePen = new Pen(Color.Black); // 创建节点的随机位置 this.beforeAttackPoint = CommonUtils.createRandomLocations(this.beforeAttackPic.Width, this.beforeAttackPic.Height, RandomAttack.DIAMETER); this.afterAttackPoint = CommonUtils.createRandomLocations(this.afterAttackPic.Width, this.afterAttackPic.Height, RandomAttack.DIAMETER); // 开始画图 // beforeAttackBm paintNode(this.beforeAttackPoint, this.beforeAttackGra, this.attackedNodeIndex, true); paintEdge(this.beforeAttackData, this.beforeAttackPoint, this.beforeAttackGra); paintNodesName(this.beforeAttackPoint, this.beforeAttackGra, this.attackedNodeIndex, true); this.beforeAttackPic.Image = this.beforeAttackBm; // afterAttackBm paintNode(this.afterAttackPoint, this.afterAttackGra, this.attackedNodeIndex, false); paintEdge(this.afterAttackData, this.afterAttackPoint, this.afterAttackGra); paintNodesName(this.afterAttackPoint, this.afterAttackGra, this.attackedNodeIndex, false); this.afterAttackPic.Image = this.afterAttackBm; // 计算攻击前后各个指标 // 计算攻击前 List <double> shorestPath; string pathStr; this.beforeCoefficient.Text = GraphUtils.getAverageClusterCoefficient(this.beforeAttackData).ToString(); this.beforeAverageDegree.Text = GraphUtils.getAverageDegree(this.beforeAttackData).ToString(); this.beforeCoreness.Text = GraphUtils.getGraphCoreness(this.beforeAttackData).ToString(); shorestPath = GraphUtils.getGraphShorestPath(this.beforeAttackData); pathStr = ""; foreach (double path in shorestPath) { pathStr += path.ToString() + " "; } this.beforeShorestPath.Text = pathStr; // 计算攻击后 this.afterCoefficient.Text = GraphUtils.getAverageClusterCoefficient(this.afterAttackData).ToString(); this.afterAverageDegree.Text = GraphUtils.getAverageDegree(this.afterAttackData).ToString(); this.afterCoreness.Text = GraphUtils.getGraphCoreness(this.afterAttackData).ToString(); shorestPath = GraphUtils.getGraphShorestPath(this.afterAttackData); pathStr = ""; foreach (double path in shorestPath) { pathStr += path.ToString() + " "; } this.afterShorestPath.Text = pathStr; }