public string ExportNode() { string contents = "{\n"; contents += "name:" + gameObject.name + "\n"; contents += "position:" + MeshMaker.ExportVector(gameObject.transform.position) + "\n"; contents += "unit:" + System.Enum.GetName(System.Type.GetType("UnitType"), unitNode.unitType) + "\n"; contents += "unit-displace:" + MeshMaker.ExportVector(unitNode.gameObject.transform.position - gameObject.transform.position) + "\n"; string slinks = "link-to:"; foreach (CLink link in links) { CNode otherNode = link.nodes.Find(x => x != this); if (otherNode.GetType() == System.Type.GetType("CountryNode")) { CountryNode country = otherNode as CountryNode; slinks += country.country.countryName + "[" + country.country.nodes.IndexOf(country).ToString() + "]"; if (links.IndexOf(link) != links.Count - 1) { slinks += ","; } //e.g. Moscow[0] would be Moscow's base node - the number really only matters for coasts, which have multiple nodes } } slinks += "\n"; contents += slinks; contents += "}\n"; return(contents); }
protected override bool Visit(ASTSymbol node) { _lastNode = new CSymbol { Name = GetVariableName(node.Name) }; return(true); }
private void ConnectNodesWithRoadNetwork(Carpooler Pooler, List <RNode> Nodes) { Nodes = Nodes.Where(x => x != null).ToList(); CNode src = null, dst = null; for (int i = 0; i < Nodes.Count - 1; ++i) { src = RoadNetwork.GetNode(Nodes[i].Point); dst = RoadNetwork.GetNode(Nodes[i + 1].Point); if (i == 0) { Pooler.SetSource(src); } Dictionary <string, string> tags = this.RoadNetwork.GetConnectionTags(src, dst); int srcArrivalTime = Pooler.GetLastArrivalTime(); int travelTime = (int)RoadNetwork.AreConnected(Nodes[i], Nodes[i + 1]).GetTravelTime(string.Empty, Pooler.GetLastArrivalTime(), TravelMode.Car); int dstArrivalTime = srcArrivalTime + travelTime; CConnection C = RoadNetwork.AddConnection(src, dst, srcArrivalTime, dstArrivalTime, ref Pooler, tags); Pooler.AddConnection(ref C); Pooler.AddNextArrivalTime(dstArrivalTime); } }
public void RemoveNode(CNode n) { if (nodes.nodes.Contains(n)) { nodes.Remove(n); } }
public void Remove(CNode c) { if (nodes.Contains(c)) { nodes.Remove(c); } }
protected override bool Visit(ASTCall node) { if (!Visit(node.Child)) { return(false); } var callee = _lastNode; var arguments = new List <CNode>(); foreach (var arg in node.Arguments) { if (!Visit(arg)) { return(false); } arguments.Add(_lastNode); } _lastNode = new CCall { Callee = callee, Arguments = arguments }; return(true); }
public Network(Genome genome) { foreach (var node in genome.Nodes.Values) { if (node.Type != NodeType.Input) { CNode cNode = new CNode(node.Id, x => (1 / (1 + Math.Exp(-x)))); Nodes[node.Id] = cNode; if (node.Type == NodeType.Output) { Outputs.Add(cNode); } } else { Inputs.Add(new ConstantProvider <double>()); } } foreach (var connection in genome.Connections.Values) { Node inputNode = genome.Nodes[connection.InputNode]; Node outputNode = genome.Nodes[connection.OutputNode]; IValueProvider <double> dependency = inputNode.Type == NodeType.Input ? Inputs[inputNode.Id] : (IValueProvider <double>)Nodes[inputNode.Id]; CNode output = Nodes[outputNode.Id]; output.AddPair(dependency, connection.Weight); } }
// Поиск потомков узла дерева сыслающегося на строку с ключом node_id private SortableObservableCollection <INode> GetChildren(int node_id, IEnumerable <Collect> list) { SortableObservableCollection <INode> tree = new SortableObservableCollection <INode>(); foreach (Collect t in list.Where(n => n.Parent_id == node_id)) { if (t.Type == "sheet") // конечный узел дерева - "лист" { CSheet sheet = new CSheet(); sheet.Id = t.Id; sheet.ParentId = t.Parent_id; sheet.Name = t.Collect_name; sheet.Dat = t.DDate; tree.Add(sheet); } else { CNode node = new CNode(); node.Id = t.Id; node.Name = t.Collect_name; node.Children = GetChildren(t.Id, list); tree.Add(node); } } tree.Sort(t => t.Name); return(tree); }
private void Delete_Click(object sender, RoutedEventArgs e) { if (treeColl.SelectedItem == null) { return; } if (treeColl.SelectedItem.GetType() == typeof(CSheet)) { CSheet node = treeColl.SelectedItem as CSheet; Collect coll = db.Collects.Find(node.Id); db.Collects.Remove(coll); db.SaveChanges(); GenerateTree(); } else { CNode node = treeColl.SelectedItem as CNode; if (node.Children.Count() > 0) { MessageBox.Show("А данного узла есть потомки, удалите сначала все дочерние узлы."); } else { Collect coll = db.Collects.Find(node.Id); db.Collects.Remove(coll); db.SaveChanges(); GenerateTree(); } } }
///////////////////////////////////////////////////////////////////////////// /// Function: AddNode ///////////////////////////////////////////////////////////////////////////// public void AddNode(CNode cNode) { if (null != cNode) { m_liConnectedNodes.Add(cNode); } }
public void writeGridToXml(CNode Grid, XmlWriter writer) { if (Grid != null) { mWriter.WriteStartElement("Cell"); mWriter.WriteAttributeString("Id", Convert.ToString(Grid.ID)); mWriter.WriteAttributeString("X", Convert.ToString(Grid.Bound.cX)); mWriter.WriteAttributeString("Y", Convert.ToString(Grid.Bound.cY)); mWriter.WriteAttributeString("Width", Convert.ToString(Grid.Bound.width)); mWriter.WriteAttributeString("Height", Convert.ToString(Grid.Bound.height)); { mWriter.WriteStartElement("Objects"); for (int i = 0; i < Grid.ListObject.Count; ++i) { mWriter.WriteStartElement("Object"); mWriter.WriteAttributeString("Type", Convert.ToString(Grid.ListObject[i].Type)); mWriter.WriteAttributeString("Id", Convert.ToString(Grid.ListObject[i].ID)); mWriter.WriteAttributeString("Index", Convert.ToString(Grid.ListObject[i].Index)); mWriter.WriteAttributeString("X", Convert.ToString(Grid.ListObject[i].Position.cX)); mWriter.WriteAttributeString("Y", Convert.ToString(Grid.ListObject[i].Position.cY)); mWriter.WriteAttributeString("Width", Convert.ToString(Grid.ListObject[i].Bound.width)); mWriter.WriteAttributeString("Height", Convert.ToString(Grid.ListObject[i].Bound.height)); mWriter.WriteEndElement(); } mWriter.WriteEndElement(); } mWriter.WriteEndElement(); } }
// Поиск в глубину public static double DFS(CNode node, CNode parent) { node.m_routes_out = 1; double result = 0; foreach (var i in node.m_branches) { var item_2 = i.Item2; if (item_2 == parent) { continue; } result += DFS(item_2, node); node.m_routes_out += item_2.m_routes_out; } foreach (var i in node.m_branches) { var item_1 = i.Item1; var item_2 = i.Item2; if (item_2 == parent) { continue; } node.m_routes_in += item_2.m_routes_in + item_1 * item_2.m_routes_out; result += (item_2.m_routes_in + item_1 * item_2.m_routes_out) * (node.m_routes_out - item_2.m_routes_out); } return(result); }
public List <CNode> GetNeighbours(CNode node) { List <CNode> neighbours = new List <CNode>(); for (int x = -1; x <= 1; x++) { for (int y = -1; y <= 1; y++) { if (x == 0 && y == 0) { continue; } int checkX = node.gridX + x; int checkY = node.gridY + y; if (checkX >= 0 && checkX < gridSizeX && checkY >= 0 && checkY < gridSizeY) { neighbours.Add(grid[checkX, checkY]); } } } return(neighbours); }
void CreateGrid() { grid = new CNode[gridSizeX, gridSizeY]; Vector3 worldBottomLeft = transform.position - Vector3.right * gridWorldSize.x / 2 - Vector3.forward * gridWorldSize.y / 2; for (var x = 0; x < gridSizeX; x++) { for (var y = 0; y < gridSizeY; y++) { Vector3 worldPoint = worldBottomLeft + Vector3.right * (x * nodeDiameter + nodeRadius) + Vector3.forward * (y * nodeDiameter + nodeRadius); bool walkable = !(Physics.CheckSphere(worldPoint, nodeRadius, unwalkableMask)); int movementPenalty = 0; Ray ray = new Ray(worldPoint + Vector3.up * 50, Vector3.down); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100, walkableMask)) { walkableRegionsDictionary.TryGetValue(hit.collider.gameObject.layer, out movementPenalty); } if (!walkable) { movementPenalty += obstacleProximityPenalty; } grid[x, y] = new CNode(walkable, worldPoint, x, y, movementPenalty); } } BlurPenaltyMap(3); }
public void GenerateGrid() { grid = new CNode[m_size_x, m_size_y]; for (int i = 0; i < m_size_x; i++) { for (int j = 0; j < m_size_y; j++) { Vector3 nodePosition = new Vector3(i * m_nodeSize + 0.5f * m_nodeSize, j * m_nodeSize + 0.5f * m_nodeSize, 0); // multiplicar es bien dividir es mal Vector3 worldPosition = nodePosition + transform.position; Collider[] colliders = Physics.OverlapSphere(worldPosition, m_nodeSize * 0.5f); bool isTransitable = true; for (int k = 0; k < colliders.Length; k++) { if (colliders[k].tag == "Wall") { isTransitable = false; } } grid[i, j] = new CNode(i, j, m_nodeSize, worldPosition, isTransitable); //grid[i, j].Grita(); } } }
// Ввод и обработка входных значений; вычисление и вывод конечного ответа public static void Main() { int number_of_points = int.Parse(Console.ReadLine()); CNode[] nodes = new CNode[50001]; for (int i = 0; i < 50001; i++) { nodes[i] = new CNode(); } for (int i = 0; i < number_of_points - 1; i++) { var entry = Console.ReadLine().Split(' '); int point_1 = int.Parse(entry[0]); int point_2 = int.Parse(entry[1]); int time = int.Parse(entry[2]); var tuple_1 = new Tuple <int, CNode>(time, nodes[point_2]); var tuple_2 = new Tuple <int, CNode>(time, nodes[point_1]); nodes[point_1].m_branches.Add(tuple_1); nodes[point_2].m_branches.Add(tuple_2); } double sum = DFS(nodes[1], nodes[0]); double answer = 2 * sum; answer /= number_of_points; answer /= (number_of_points - 1); Console.Write(answer); }
public static bool NoCircularProductions() { bool ok, changed, onLeftSide, onRightSide; ArrayList list = new ArrayList(); foreach (Symbol sym in Symbol.nonterminals) { ArrayList singles = new ArrayList(); GetSingles(sym.graph, singles); // get nonterminals s such that sym-->s foreach (Symbol s in singles) list.Add(new CNode(sym, s)); } do { changed = false; for (int i = 0; i < list.Count; i++) { CNode n = (CNode)list[i]; onLeftSide = false; onRightSide = false; foreach (CNode m in list) { if (n.left == m.right) onRightSide = true; if (n.right == m.left) onLeftSide = true; } if (!onLeftSide || !onRightSide) { list.Remove(n); i--; changed = true; } } } while(changed); ok = true; foreach (CNode n in list) { ok = false; Errors.count++; Console.WriteLine(" {0} --> {1}", n.left.name, n.right.name); } return ok; }
//------------------------------------------------------------------------- // 添加子Node public void _addChildNode(CNode node) { if (!mMapAllChild.ContainsKey(node.getNodeId())) { mMapAllChild.Add(node.getNodeId(), node); } }
public void append(string data) { CNode customNode = new CNode(data); //check if head is null if (head == null) { head = customNode; head.Next = null; head.Previous = null; nodeCount++; return; } else { current = head; //walk through the list while (current.Next != null) { current = current.Next; } current.Next = customNode; customNode.Previous = current; tail = customNode; nodeCount++; } }
public void EstablishLink(CNode nodeA, CNode nodeB, CanvasCreator parent) { parentCC = parent; parentCC.links.Add(this); gameObject.name = "Link " + parentCC.links.Count.ToString(); gameObject.transform.Translate(Vector3.back / 2); nodes.Add(nodeA); nodeA.links.Add(this); nodes.Add(nodeB); nodeB.links.Add(this); Mesh lineMesh = gameObject.AddComponent <MeshFilter> ().mesh; lineMesh.vertices = new Vector3[4]; lineMesh.triangles = new int[6] { 0, 1, 2, 0, 2, 3 }; DrawLink(); MeshRenderer newRenderer = gameObject.AddComponent <MeshRenderer> (); newRenderer.material.color = nodeB.LinkColor(); newRenderer.material.shader = Shader.Find("UI/Default"); gameObject.AddComponent <MeshCollider> (); }
private void ConnectionDrawing(CNode n) { Event e = Event.current; if (connectionDragging != null) { Vector2 nC = connectionDragging.connecterBox.center; float hC = connectionDragging.pos.height; Handles.DrawBezier(nC, e.mousePosition, nC + Vector2.up * hC, e.mousePosition + Vector2.down * hC, connectionDragging.tag, null, 5); } for (int i = 0; i < deleted.Count; i++) { if (n.connected.Contains(i)) { n.connected.Remove(i); } } for (int i = 0; i < n.connected.Count; i++) { if (n.connected[i] == null || n.hidden || n.childrenHidden || ni(n.connected[i]).hidden) { continue; } Handles.BeginGUI(); Vector2 nC = n.connecterBox.center; float hC = n.pos.height / 2; Vector2 nR = ni(n.connected[i]).recieverBox.center; float hR = n.pos.height / 2; Handles.DrawBezier(nC, nR, nC + Vector2.up * hC, nR + Vector2.down * hR, n.tag, null, 5); Handles.EndGUI(); } }
private void OutOfScreenCheck(CNode w) { Rect s = position; if (w.pos.y > nAdder.yMin || w.pos.x > inspector.xMin || w.pos.x < 0 || w.pos.y < 0) { w.tagOverride = true; Vector2 pos = w.tagR.position; if (w.pos.y < 0) { pos.y = 0; } else if (w.pos.y > nAdder.yMin) { pos.y = nAdder.yMin - 10; } if (w.pos.x < 0) { pos.x = 0; } else if (w.pos.x > inspector.xMin) { pos.x = inspector.xMin - 10; } w.oTag = new Rect(pos, new Vector2(10, 10)); } else { w.tagOverride = false; } }
public void Clear() { head = null; Count = 0; GC.Collect(); }
protected override bool Visit(ASTFloatLiteral node) { _lastNode = new CFloatLiteral { Value = node.Value }; return(true); }
protected override bool Visit(ASTIntegerLiteral node) { _lastNode = new CIntegerLiteral { Value = node.Value }; return(true); }
public void MergeInto(Country other) { if (other == this) { return; } while (territories.Count > 0) { AddTo(territories[0], other); } while (nodes.Count > 0) { CountryNode node = nodes[0]; foreach (CLink link in node.links) //Merge the other links made into this one { CNode otherNode = link.nodes.Find(x => x != node && x.GetType() != System.Type.GetType("UnitNode")); if (otherNode != null) { other.nodes[0].EstablishLink(otherNode); } } nodes.Remove(node); GameObject.Destroy(node.gameObject); } faction = null; territories = null; Camera.main.GetComponent <CanvasCreator> ().countries.Remove(this); }
public CNode GetNode(Point P, string stopName = "") { if (CNodes == null) { this.CNodes = new Dictionary <long, CNode>(); this.CConnections = new Dictionary <long, CConnection>(); } long id = CNodes.Count; if (id != 0) { id = CNodes.Aggregate((l, r) => l.Key > r.Key ? l : r).Key; } var c = CNodes.Where(x => x.Value.Point == P).FirstOrDefault().Value; if (c == null) { var n = new CNode(id + 1, P, stopName); CNodes.Add(n.Id, n); return(n); } else { return(c); } }
public void EstablishLink(CNode nodeA, CNode nodeB, CanvasCreator parent) { parentCC = parent; parentCC.links.Add (this); gameObject.name = "Link " + parentCC.links.Count.ToString (); gameObject.transform.Translate (Vector3.back / 2); nodes.Add (nodeA); nodeA.links.Add (this); nodes.Add (nodeB); nodeB.links.Add (this); Mesh lineMesh = gameObject.AddComponent<MeshFilter> ().mesh; lineMesh.vertices = new Vector3[4]; lineMesh.triangles = new int[6] {0, 1, 2, 0, 2, 3}; DrawLink (); MeshRenderer newRenderer = gameObject.AddComponent<MeshRenderer> (); newRenderer.material.color = nodeB.LinkColor (); newRenderer.material.shader = Shader.Find ("UI/Default"); gameObject.AddComponent<MeshCollider> (); }
//------------------------------------------------------------------------- public CNodeStateStop(CNode node) { mNode = node; _defState("CNodeStateStop", "EbFsm", 0, false); _bindAction("evSetNextState", new EbAction(this.evSetNextSate)); }
//------------------------------------------------------------------------- public CNodeStateInit(CNode node) { mNode = node; _defState("CNodeStateInit", "EbFsm", 0, true); _bindAction("evSetNextState", new EbAction(this.evSetNextSate)); }
public NodeWindow(CNode p) { InitializeComponent(); _node = p; dPicker.Visibility = Visibility.Hidden; dText.Visibility = Visibility.Hidden; this.DataContext = _node; }
//Given a node, fans a recursive tree out to catch all nodes connected by links to it void ConnectedNodes(CNode startingNode, List<CNode> toIgnore) { toIgnore.Add (startingNode); foreach (CNode otherNode in startingNode.ConnectedTo()) { if(!toIgnore.Contains(otherNode)) { ConnectedNodes(otherNode, toIgnore); } } }
//------------------------------------------------------------------------- public CNodeStateRun(CNode node) { mNode = node; _defState("CNodeStateRun", "EbFsm", 0, false); _bindAction("main_update", new EbAction(this.evMainUpdate)); _bindAction("main_sendmsg", new EbAction(this.evMainSendMsg)); _bindAction("evSetStopState", new EbAction(this.evSetStopState)); }
public override bool CanEstablishLink(CNode other, CLink checkLink) { /* bool countryBlock = false; if (other.GetType () == System.Type.GetType ("CountryNode")) { CountryNode otherCountry = other as CountryNode; countryBlock = (otherCountry.country == country); }*/ return !checkLink.nodes.Contains (this); }
//------------------------------------------------------------------------- // 更新队列中所有Node操作 public void updateQueNodeOp() { while (mQueNodeOp.Count > 0) { _tNodeOp node_op = mQueNodeOp.Dequeue(); switch ((_eNodeOp)node_op.op) { case _eNodeOp.CreateNode: { if (!mIsClient) { mQueNodeOpRemote.Enqueue(node_op); } if (!mMapAllNode.ContainsKey(node_op.id)) { CNode node = new CNode(); node.create(node_op.id, (_eNodeState)node_op.state, node_op.list_param, mpNodeServerListener, mpNodeClientListener, mNodeSys, this); mMapAllNode[node.getNodeId()] = node; } } break; case _eNodeOp.DestroyNode: { if (!mIsClient) { mQueNodeOpRemote.Enqueue(node_op); } if (mMapAllNode.ContainsKey(node_op.id)) { CNode node = mMapAllNode[node_op.id]; mMapAllNode.Remove(node_op.id); node.Dispose(); } } break; case _eNodeOp.EnterState: { if (!mIsClient) { // Server mQueNodeOpRemote.Enqueue(node_op); } else if (mMapAllNode.ContainsKey(node_op.id)) { // Client CNode node = mMapAllNode[node_op.id]; node.setNodeSate(node_op); } } break; } } }
//------------------------------------------------------------------------- public CNodeStateRelease(CNode node) { mNode = node; _defState("CNodeStateRelease", "EbFsm", 0, false); }
//------------------------------------------------------------------------- public abstract INodeClientScript createScript(CNode entity);
//------------------------------------------------------------------------- public abstract void onServer2ClientMsg(CNode node, int msg_type, int msg_id, int msg_param, List<object> msg_paramlist);
//------------------------------------------------------------------------- public abstract void onDoEffect(CNode node, int exit_id);
//------------------------------------------------------------------------- public abstract INodeServerScript createScript(CNode node, Entity entity_player);
public override bool CanEstablishLink(CNode other, CLink checkLink) { return links.Count == 0; }
//------------------------------------------------------------------------- public abstract void onEnterRunState(CNode entity);
//------------------------------------------------------------------------- public abstract void onEnterStartState(CNode entity);
//------------------------------------------------------------------------- public INodeClientScript(INodeClientScriptFactory factory, CNode entity) { mFactory = factory; mNode = entity; }
//------------------------------------------------------------------------- public INodeServerScript(INodeServerScriptFactory factory, CNode node, Entity entity_player) { mFactory = factory; mNode = node; mEntityPlayer = entity_player; }
//------------------------------------------------------------------------- public abstract bool canExitStartState(CNode node);
//------------------------------------------------------------------------- public void create(int node_id, _eNodeState state, List<_tNodeParamPair> list_param, INodeServerListener server_listener, INodeClientListener client_listener, CNodeSys node_sys, CNodeMgr node_mgr) { mNodeServerListener = server_listener; mNodeClientListener = client_listener; mNodeSys = node_sys; mNodeMgr = node_mgr; // 初始化NodeInfo mNodeId = node_id; mNodeState = state; if (list_param != null) { foreach (var i in list_param) { if (i.k == (byte)_eNodeParam.PreNodeId || i.k == (byte)_eNodeParam.ExitId) { mMapParam[i.k] = int.Parse(i.v.ToString()); } else { mMapParam[i.k] = i.v; } } } // 加载DefXml数据 _loadDefXml(); // 设置该Node的父Node string str_parent_node_id = getDefXml().GetValue("Parent").Value; if (str_parent_node_id != string.Empty && str_parent_node_id != "0") { int parent_node_id = Convert.ToInt32(str_parent_node_id); CNode node_parent = getNodeMgr().findNode(parent_node_id); if (node_parent != null) { mParentNode = node_parent; node_parent._addChildNode(this); } } // 从xml中解析所有trigger _parseTriggerXml(); // 初始化脚本 if (mNodeSys.isClient()) { INodeClientScriptFactory factory = mNodeSys.getNodeClientScriptFactory(getNodeType()); if (factory != null) { mNodeClientScript = factory.createScript(this); } } else { INodeServerScriptFactory factory = mNodeSys.getNodeServerScriptFactory(getNodeType()); if (factory != null) { mNodeServerScript = factory.createScript(this, getEtPlayer()); } } // 创建Fsm addState(new CNodeStateInit(this)); addState(new CNodeStateStart(this)); addState(new CNodeStateRun(this)); addState(new CNodeStateStop(this)); addState(new CNodeStateRelease(this)); setupFsm(); }
//------------------------------------------------------------------------- public abstract void onUpdate(CNode node, float elasped_tm);
//------------------------------------------------------------------------- public abstract void onEnterStopState(CNode node);
//------------------------------------------------------------------------- public abstract void onEnterRunState(CNode node);