static void Main(string[] args) { graph g = new graph(); graphnode node5 = new graphnode(5); graphnode node4 = new graphnode(4); graphnode node2 = new graphnode(2); graphnode node0 = new graphnode(0); graphnode node1 = new graphnode(1); graphnode node3 = new graphnode(3); g.graphnodelist = new List <graphnode> { node5, node4, node2, node0, node1, node3 }; g.addDirectedEdge(node5, node2); g.addDirectedEdge(node5, node0); g.addDirectedEdge(node4, node0); g.addDirectedEdge(node4, node1); g.addDirectedEdge(node2, node3); g.addDirectedEdge(node3, node1); Stack <int> s = new Stack <int>(); topologicalSort(g, ref s); Console.WriteLine(s.ToList()); }
static void Main(string[] args) { graph g = new graph(); /* * System.Random r = new System.Random(); * for( int i = 0 ; i < 10000 ; i++ ){ * //g.line( r.Next(800),r.Next(800), r.Next(800),r.Next(800) ); * g.pset( r.Next(800),r.Next(800) ); * } */ for (int i = 0; i < 800; i++) { g.pset(i, i); } g.lcolor(0, 0, 0); for (int i = 0; i < 800; i += 10) { g.pcolor(i % 255, 0, 0); g.rect(i, i, 100, 100); } g.lcolor(0, 255, 255); for (int i = 0; i < 800; i += 10) { g.pcolor(0, i % 255, 0); g.oval(i, 400, 100, 100); } g.lcolor(255, 0, 0); for (int i = 0; i < 800; i += 10) { g.pcolor(0, 0, i % 255); g.rect(i, 800 - i, 100, 100); } }
public graph G(bool scan) { if (this.raftNode.current_state == Raft.Node.State.Leader) //CONSULTAS NÃO FAZEM COMITIS APENAS VALIDAM SE O NODO É O LIDER, APENAS UM LIDER PODE CONVERSAR COM O CLIENTE. { if (!scan || this.servers.Count() == 1) { return(this.g); } graph G = new graph(); foreach (string server in this.servers.Keys) { TTransport transport = new TSocket(server.Split(':')[0], int.Parse(server.Split(':')[1])); TProtocol protocol = new TBinaryProtocol(transport); Thrift.TheGraph.Client client = new Thrift.TheGraph.Client(protocol); transport.Open(); G.V.AddRange(client.G(false).V); G.E.AddRange(client.G(false).E); transport.Close(); } return(G); } else { Console.WriteLine("APENAS LIDERES PODEM CONSULTAR"); return(null); } }
/// <summary> /// Sends the color chosen for a specific curve to the graphHandler /// </summary> /// <param name="comboBox">The comboBox where a color is selected in</param> /// <param name="graphToDraw">The curve that is to be colored with the specified color</param> private void colorChoice(ComboBox comboBox, graph graphToDraw) { switch ((colors)comboBox.SelectedItem) { case colors.Rød: ChangeGraphColor(Color.Red, graphToDraw); break; case colors.Grøn: ChangeGraphColor(Color.Green, graphToDraw); break; case colors.Blå: ChangeGraphColor(Color.Blue, graphToDraw); break; case colors.Lilla: ChangeGraphColor(Color.Purple, graphToDraw); break; case colors.Sort: ChangeGraphColor(Color.Black, graphToDraw); break; default: break; } }
public static graph calculateShortestPathFromSource(graph routeGraph, node source) { source.setDistance(0); LinkedList <node> settledNodes = new LinkedList <node>(); LinkedList <node> unsettledNodes = new LinkedList <node>(); unsettledNodes.AddLast(source); while (unsettledNodes.Count != 0) { node currentNode = getLowestDistanceNode(unsettledNodes); unsettledNodes.Remove(currentNode); foreach (KeyValuePair <node, float> entry in currentNode.adjacentNodes) { node adjacentNode = entry.Key; if (!settledNodes.Contains(adjacentNode)) { calculateMinimumDistance(adjacentNode, entry.Value, currentNode); unsettledNodes.AddLast(adjacentNode); } } settledNodes.AddLast(currentNode); } return(routeGraph); }
static void Main(string[] args) { graph g = new graph(); graphnode node5 = new graphnode(5); graphnode node4 = new graphnode(4); graphnode node2 = new graphnode(2); graphnode node0 = new graphnode(0); graphnode node1 = new graphnode(1); graphnode node3 = new graphnode(3); g.graphnodelist = new List <graphnode> { node5, node4, node2, node0, node1, node3 }; g.addDirectedEdge(node5, node2); g.addDirectedEdge(node5, node0); g.addDirectedEdge(node4, node0); g.addDirectedEdge(node4, node1); g.addDirectedEdge(node2, node3); g.addDirectedEdge(node3, node1); bool res = FindPathBetweenTwoGraphNode(node5, node1); graph.resetGraphnodevistedboolean(g); bool res2 = FindPathBetweenTwoGraphNode(node2, node1); graph.resetGraphnodevistedboolean(g); bool res3 = FindPathBetweenTwoGraphNode(node5, node4); }
private void ResetMapGroup(graph graph2) { foreach (var node in graph2.nodes) { // GetImage(node.label).color = node.adjecent.Count == 0 ? Color.white : Color.grey; } }
public Handler(string ip, int port, bool first, int serverIndex, List <Tuple <string, List <int> > > nodes) { #region VARIAVEIS DE CONTROLE DA COMUNICAÇÃO MULTICAST PARA CONTROLE DE SERVIDOR this.ip = ip; this.port = port; this.MyAddress = string.Format("{0}:{1}", ip, this.port); this.first = first; this.UDPClient = new System.Net.Sockets.UdpClient(); this.MulticastAddress = IPAddress.Parse("224.5.6.7"); this.SenderEndPoint = new IPEndPoint(MulticastAddress, 2222); this.ReceiverEndPoint = new IPEndPoint(IPAddress.Any, 2222); this.UDPClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); //PERMITE MULTIPLOS SERVIDORES RODAREM NO MESMO COMPUTADOR this.UDPClient.JoinMulticastGroup(MulticastAddress); this.UDPClient.Client.Bind(ReceiverEndPoint); #endregion #region VARIAVEL DE CONTROLE DO RAFT var nodeServer = nodes.Where(n => n.Item1 == ip); if (!nodeServer.Any()) { throw new Exception("CONFIGURAÇÃ DE NODOS DO RAFT INVALIDA, O SERVIDOR ATUAL NÃO ESTÁ LISTADO"); } if (nodeServer.Count() > 1) { var ports = nodeServer.SelectMany(node => node.Item2); var portsDistinct = ports.Distinct(); if (ports.Count() != portsDistinct.Count()) { throw new Exception("CONFIGURAÇÃ DE NODOS DO RAFT INVALIDA, UMA PORTA ESTÁ SENDO USADA MAIS DE UMA VEZ PARA UM MESMO SERVIDOR"); } if (ports.Any(p => p == this.port)) { throw new Exception("CONFIGURAÇÃO DE NODOS DO RAFT INVALIDA A MESMA PORTA FOI DIRECIONADA TANTO PARA O RAFT QUANTO PARA O SERVIDOR THRIFT!"); } } this.raftNode = new Raft.Node(nodes, serverIndex, this); raftNode.run(); //COLOCA O RAFT PRA RODAR EM THREAD SEPARADA #endregion //DICIONARIOS DO TIPO <IP:PORT> => BIT DE INICIO DO INTERVALO E BIT DE FIM. Ex: {127.0.0.1:8080, <0, 10>} //ONDE O SERVIDOR 127.0.0.1:8080, IRA RECEBER OS NODOS ONDE HASH(ID) >= 2^0 && HASH(ID) < 2^10 this.servers = new Dictionary <string, Tuple <int, int> >(); //INSTANCIA DO GRAFO, ESTRUTURA QUE IRA MANTER OS REGISTROS NA MEMORIA this.g = new graph(); //MUTEX UTILIZADOS PARA CONTROLE DE CONCORRENCIA ENTRE AS MUITAS THREADS this.MUTEX_E = new System.Threading.Mutex(); this.MUTEX_V = new System.Threading.Mutex(); this.MUTEX_S = new System.Threading.Mutex(); }
public Form1() { InitializeComponent(); chart1.MouseWheel += new MouseEventHandler(ch1_MouseWheel); chart1.MouseClick += new MouseEventHandler(ch1_MouseClick); chart2.MouseClick += new MouseEventHandler(ch2_MouseClick); timeGraph = new graph(graphDFT); freqGraph = new inverse(graphInverse); }
private static List <int> topologicalSort(graph g, ref Stack <int> s) { foreach (graphnode node in g.graphnodelist) { if (!node.visited) { topologicalSortHelper(node, ref s); node.visited = true; } } return(s.ToList()); }
private void OnLineGraph_Load(object sender, EventArgs e) { ////////graph///// m_simGraph = new graph(pictureBox.Size, pictureBox); m_simGraph.InitGraph(5, 1); ConfigureGraph1(); //fill_Combo(); //InitLitView(); //int Rn = 0; // while (Rn < 125) // { // listBox1.Items.Add(Global.PNo[Rn].ToString() + " " +Global.PSName[Rn].ToString()); // Rn += 1; // } }
/* * window * * Checks which windowing fucntion to use and calls it based on radio buttons. * * Parameter: * sender * e * * return void */ public void window() { double[] winSample, winSample2 = null; Thread dft = null; A = new Complex[range]; winSample = new double[range]; Array.Copy(left, offset, winSample, 0, range); if (right != null) { A2 = new Complex[range]; winSample2 = new double[range]; Array.Copy(right, offset, winSample2, 0, range); } if (!SqrBtn.Checked) { if (TriBtn.Checked) { Windowing.Triangle(ref winSample, range); //chart2.Series["Series1"].Points.Clear(); dft = new Thread(() => Fourier.DFT(winSample, winSample2, ref A, ref A2, this)); } if (HamBtn.Checked) { Windowing.Hamming(ref winSample, range); //chart2.Series["Series1"].Points.Clear(); dft = new Thread(() => Fourier.DFT(winSample, winSample2, ref A, ref A2, this)); } } else { // chart2.Series["Series1"].Points.Clear(); dft = new Thread(() => Fourier.DFT(winSample, winSample2, ref A, ref A2, this)); } if (dft != null) { dft.Start(); } }
GetRowsAndColumns ( ICollection <IVertex> oVerticesToLayOut, LayoutContext oLayoutContext, out Int32 iRows, out Int32 iColumns ) { Debug.Assert(oVerticesToLayOut != null); Debug.Assert(oLayoutContext != null); AssertValid(); #if false Some definitions: W = rectangle width H = rectangle height A = rectangle aspect ratio = W / H V = number of vertices in graph Vrow = number of vertices per row Vcol = number of vertices per column R = number of grid rows = Vcol + 1 C = number of grid columns = Vrow + 1 First simulataneous equation, allowing Vrow and Vcol to be fractional for now: Vrow * Vcol = V Second simulataneous equation: C / R = A Combining these equations yield this quadratic equation: 2 C + [(-A - 1) * C] +[A * (1 - V)] = 0
public graph createGraph() { graph grafo = new graph(); Debug.Log(triangles.Count); foreach (triangle t1 in triangles) { foreach (triangle t2 in triangles) { if (t1 != t2) { bool found = false; Vector3[] points = { t1.v1, t1.v2, t1.v3 }; foreach (Vector3 p in points) { bool cond1 = pointInLine(p, t2.v1, t2.v3, 0.01f); bool cond2 = pointInLine(p, t2.v2, t2.v3, 0.01f); bool cond3 = pointInLine(p, t2.v1, t2.v2, 0.01f); if (cond1 || cond2 || cond3) { found = true; break; } } if (found) { //Debug.Log ("encontrado"); float peso = distBetweenPoints(t1.center, t2.center); Vector3 aux = t2.center; aux.z = peso; if (grafo.connections.ContainsKey(t1.center)) { grafo.connections [t1.center].Add(aux); } else { grafo.connections [t1.center] = new List <Vector3> (); grafo.connections [t1.center].Add(aux); } } } } } return(grafo); }
void OnGUI() { if (!hecho) { foreach (Transform child in transform) { //child is your child transform BoxCollider boxC = child.GetComponent <BoxCollider>(); Bounds bs = boxC.bounds; Vector3 tl = new Vector3(bs.center.x - bs.extents.x, bs.center.y + bs.extents.y, 0f); Vector3 br = new Vector3(bs.center.x + bs.extents.x, bs.center.y - bs.extents.y, 0f); List <triangle> list_ini = squareToTriangle(tl, br); int iter = 0; while (true) //list_ini.Count>0 { triangle tr = list_ini [0]; DrawTriangle(tr.v1, tr.v2, tr.v3, Color.white, 200000f); if (iter < 40) { List <triangle> new_trs = splitTriangle(tr); foreach (triangle trr in new_trs) { list_ini.Add(trr); } iter++; } else if (iter == 40) { Debug.Log(list_ini.Count); foreach (triangle t in list_ini) { triangles.Add(t); } //triangles = list_ini; break; } list_ini.RemoveAt(0); } } Debug.Log(triangles.Count); hecho = true; graph gf = createGraph(); Debug.Log(gf.connections.Count); } }
// Use this for initialization public void Start() { startpoint = pathfindingend.temp; //startpoint = 5; int[,] map = new int[5, 5] { { 0, 1, 0, 0, 0 }, { 0, 1, 0, 0, 0 }, { 0, 1, 0, 0, 0 }, { 0, 1, 0, 0, 0 }, { 0, 0, 0, 0, 0 } }; var graph = new graph(map); var search = new search(graph); //endpoint = 0; //startpoint = 23; // Apoint = enemyfollow.target; //Debug.Log("StartPoint = " + startpoint); //Debug.Log("EndPoint " + endpoint); search.start(graph.nodes[endpoint], graph.nodes[startpoint]); while (!search.finished) { search.Step(); } // print("Search done.Path Length " + search.path.Count + " iterations" + search.iterations); ResetMapGroup(graph); foreach (var node in search.path) { GetImage(node.label).color = node.adjecent.Count == 0 ? Color.white : Color.white; } foreach (var node in search.path) { GetImage(node.label).color = Color.red; } }
public graph creategraph(String type) { graph newgraph = null; if (type.Equals("Rectangle")) { newgraph = new Rectangle(); } else if (type.Equals("Square")) { newgraph = new Square(); } else if (type.Equals("Circle")) { newgraph = new Circle(); } else if (type.Equals("Triangle")) { newgraph = new Triangle(); } return(newgraph); }
/* * Form1 constructor * * Constructor for the main form * */ public Form1() { InitializeComponent(); dft = new graph(graphDFT); inv = new inverse(graphInverse); inv2 = new inverse2(graphInverse2); btnEnble = new enable(EnableButtons); chart1.MouseWheel += new MouseEventHandler(chData_MouseWheel); chart2.MouseWheel += new MouseEventHandler(chData2_MouseWheel); chart3.MouseWheel += new MouseEventHandler(chData3_MouseWheel); chart4.MouseWheel += new MouseEventHandler(chData4_MouseWheel); chart1.MouseClick += new MouseEventHandler(chart1_MouseClick); chart2.MouseClick += new MouseEventHandler(chart2_MouseClick); chart3.MouseClick += new MouseEventHandler(chart3_MouseClick); chart4.MouseClick += new MouseEventHandler(chart4_MouseClick); tableLayoutPanel1.RowStyles[1].Height = 0; tableLayoutPanel2.RowStyles[1].Height = 0; // Disable data relient buttons button2.Enabled = false; button3.Enabled = false; button4.Enabled = false; PlayBtn.Enabled = false; StopBtn.Enabled = false; WndBtn.Enabled = false; FilterBtn.Enabled = false; exportToolStripMenuItem.Enabled = false; cutToolStripMenuItem.Enabled = false; copyToolStripMenuItem.Enabled = false; this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true); this.UpdateStyles(); }
/// <summary> /// Changes the color of the selected graph. /// </summary> /// <param name="col">Color.</param> /// <param name="enumGraph">Enum graph.</param> public void ChangeGraphColor(Color col, graph enumGraph) { switch (enumGraph) { case graph.ammonia: synth.graphHandlers[pTabs.SelectedIndex].ChangeAmmoniaColor(col); break; case graph.hydrogen: synth.graphHandlers[pTabs.SelectedIndex].ChangeHydrogenColor(col); break; case graph.nitrogen: synth.graphHandlers[pTabs.SelectedIndex].ChangeNitrogenColor(col); break; case graph.temperature: synth.graphHandlers[pTabs.SelectedIndex].ChangeTemperatureColor(col); break; default: throw new IndexOutOfRangeException(); } }
GraphMemberType.CacheAttached => new CacheAttachedCategoryNodeViewModel(graph, ExpandCreatedNodes),
public search(graph graph1) { this.graph1 = graph1; }
CanReach(graph, newEdge.Node2, newEdge.Node1);
public void findChild(ref int[,] Weights, ref int[,] Amount) { for (; !cycle_is_finded && child_exists(ref Weights, ref Amount);) { if (cycle_is_finded) { break; } switch (state) { case "up": { for (int i = a - 1; i >= 0; i--) { if (Amount[i, b] != 0 && !cycle_is_finded) { num_of_childs++; up = true; way[depth - 1, 0] = i; way[depth - 1, 1] = b; Array.Resize(ref child, num_of_childs); child[num_of_childs - 1] = new graph(i, b, a, b, depth, state); child[num_of_childs - 1].findChild(ref Weights, ref Amount); } } break; } case "down": { for (int i = a + 1; i < 4; i++) { if (Amount[i, b] != 0 && !cycle_is_finded) { down = true; num_of_childs++; way[depth - 1, 0] = i; way[depth - 1, 1] = b; Array.Resize(ref child, num_of_childs); child[num_of_childs - 1] = new graph(i, b, a, b, depth, state); child[num_of_childs - 1].findChild(ref Weights, ref Amount); } } break; } case "right": { for (int i = b + 1; i < 4; i++) { if (Amount[a, i] != 0 && !cycle_is_finded) { right = true; num_of_childs++; way[depth - 1, 0] = a; way[depth - 1, 1] = i; Array.Resize(ref child, num_of_childs); child[num_of_childs - 1] = new graph(a, i, a, b, depth, state); child[num_of_childs - 1].findChild(ref Weights, ref Amount); } } break; } case "left": { for (int i = b - 1; i >= 0; i--) { if (Amount[a, i] != 0 && !cycle_is_finded) { left = true; num_of_childs++; way[depth - 1, 0] = a; way[depth - 1, 1] = i; Array.Resize(ref child, num_of_childs); child[num_of_childs - 1] = new graph(a, i, a, b, depth, state); child[num_of_childs - 1].findChild(ref Weights, ref Amount); } } break; } } } }
GraphMemberType.BaseMemberOverride => new GraphBaseMemberOverridesCategoryNodeViewModel(graph, ExpandCreatedNodes),
(start) => SPFUtility(graph, start);
GraphMemberType.PXOverride => new PXOverridesCategoryNodeViewModel(graph, ExpandCreatedNodes),
GraphMemberType.FieldEvent => new FieldEventCategoryNodeViewModel(graph, ExpandCreatedNodes),
GraphMemberType.InitializationAndActivation => new GraphInitializationAndActivationCategoryNodeViewModel(graph, ExpandCreatedNodes),
GraphMemberType.Action => new ActionCategoryNodeViewModel(graph, ExpandCreatedNodes),
GraphMemberType.View => new ViewCategoryNodeViewModel(graph, ExpandCreatedNodes),