I am modelling a network in netlogo and each node has 4 linked nodes (like a mesh). I want to take some value from only the left (west) linked node. How do I do this? If I say link-neighbors then all the linked neighbors get selected but I want to do this operation on only specific linked neighbor.
Since your nodes are fixed to patches, you can take advantage of the in-built coordinate system. All nodes have a pair of variables xcor and ycor, and patches have pxcor and pycor. If your nodes are always exactly in the centre of a patch, you could simply find the link-neighbor with the xcor that is exactly 1 less than the xcor of the asking node. But a more general solution is to find the linked node that is most to the west (which is equivalent to the one with the lowest value for xcor).
Here is some (untested) example code that just colours a node and its west neighbour, and prints a variable value of the west neighbour.
ask one-of nodes
[ set color red
let left-node min-one-of link-neighbors [xcor]
ask left-node [ set color blue ]
type "Colour of west node is: " print [color] of left-node
]
Related
I am trying to do the following:
Let's say this is the initial graph: Initial Graph
I want to get all the blue nodes between red nodes and connect them to a new yellow node. I want to do this for every blue node area seperated by red nodes.
What I am trying to tell: The Result I Want
I want to do this without creating redundant yellow nodes and unnecessary traversals. Also, I want to do this in a single query, if it is possible.
Initially I achieved creating yellow nodes and connecting them by getting paths which start with a red node and end with another red node. However, this solution led to creating redundant yellow nodes since there are some areas seperated by 3 or more red nodes. For instance if a blue node area is seperated by 3 red nodes, this solution finds 3 different paths in that area, therefore creates 3 different yellow nodes. So I had to delete redundant yellow nodes in another query which was terrible in terms of efficiency.
After that, I tried using apoc expand functions, however they require minLevel and maxLevel parameters which again leads to finding more than one path in a blue node area.
In short, the real question is how can I achieve getting each blue node area as a single path without compromising efficiency?
Edit: I also tried creating a yellow node for each blue node directly connected to the red node near it and then connected the other blue nodes to the yellow node if they are reachable through blue nodes, however this query also takes too much time.
As far as I am concerned matching paths like the following query affects time efficiency too negatively:
MATCH path = (:YELLOW)-[link*]-(:BLUE)-[:CONNECTION]-(:RED)
WHERE single(x IN nodes(path) WHERE x:RED)
//Then connect nodes in path to the yellow node if there is no connection
Any suggestions?
I am trying to solve with Comsol the problem of the figureTwo blue big electrodes with fixed potentials V1,V2. One red small electrode that moves above the others along x axis at constant distance and voltage V0. The charge in V0 depends on the electric field at each point 8(x). I have one small electrode with a potential V0 moving along x axis above two bigger electrodes with fixed potentials V1,V2.
I can easily compute with comsol the potential and field at each point in 3D and the resulting charge in V0 electrode. However i would like to simulate this charge along the x axis and eventually map it also for z and y direction so i have a V0 charge 2D map at a fixed distance.
How can i do this in COMSOL without changing the geometry coordinates manually and computing again the charge at each point?
Thank you for your answers,
Jorge
I'll describe how to setup the system so that you can move V0 around. Note that this requires changing the mesh throughout the simulation. For this reason, I don't think you want a "time dependent" study but instead you want to use the "parametric sweep" option.
First, go to your Global Parameters and create a parameter called block_x_pos or whatever you want.
Go to Component → Geometry and select V0 and in the appropriate field under the "Position" tab (in the Setting Panel), write block_x_pos in the X Position. This makes that position controllable by whatever value is in block_x_pos.
Right click on the appropriate Study and select "Parametric Sweep". The purpose (as far as I know) for the Parametric Sweep is that when the geometry is changing during computation, it updates the mesh accordingly, so you don't have to do it manually through some painful repetition. Select the "Parametric Sweep" node which has now appeared. Look in the Settings Panel and find the "Study Settings" tab. Below the empty table, you'll see some arrows and a "+" sign. Click the "+". This will add a new sweep parameter to the table. Click the dropdown menu on the table and select the "time" Global Parameter. In the "Parameter Value List" field, write the range of values you'd like to have it take.
i.e. if you want the block_x_pos parameter to vary from 0 to 10 in steps of 0.1, you would write range(0, 0.1, 10). Or you could write '-3 0 1 2 4 5 9 11' and it will take those values.
Now Compute using that same Study.
When you are making plots, be sure to use the correct Solution. It will be labeled something like "Study1/ParametricSolutions1". When you select this as your "Data Set", you will find (in your Settings Panel) a new dropdown menu below the "Data Set" field called "Parametric selection (time)". You can choose to show multiple values for the "time" parameter on most plot types.
Finding the shortest path between 2 points namely S and G? It SHOULD pass through points named #. The allowed pathway is denoted as . and the blocked pathway is denoted as #. The upper cap of the number of points inbetween is 19.
Example:
input
########
##....G#
##.#####
#..#..S#
##.....#
########
"It should pass through points named #" - If you can elaborate more on this. OR for the example above, what is the expected solution.
Also statement says "blocked pathway is denoted as X" and in example, we see "#". I believe you meant # as X.
I assume direction of movement would be left, right, up and down.
This can be solved by breadth first search (BFS) on the grid.
Start from S and explore all paths level by level based on given constraint where you can reach and where you can't reach.
We can take two arrays or lists say currentLevel and nextLevel. And a variable, say levelCount.
Store position S in currentLevel.
Loop through positions in currentLevel one by one. If it is G, levelCount is the shortest path.
Else, for all safe positions (left, right, up and down) where we can reach and store them in
nextLevel. "safe position" means that it should not be X, should not go beyond the given
grid extent (i.e. position index should not less than zero and not greater than length)
or other constraint given in problem.
Set currentLevel to nextLevel, increment levelCount and clear nextLevel. Go to step 1.
Consider the following subgraph, with 5 Mrecod nodes:
Is there a way to force a vertical orientation, with the nodes above each other? I've tried rankdir=TB in the subgraph, with no effect.
I am running graphviz under Ubuntu with no special parameters:
dot -Tpng graph.dot -o img/graph.png
Adam, just to clear up a couple of potentially confusing points:
I'm pretty sure that the rankdir attribute applies to the entire graph, you cannot isolate that particular subgraph.
rankdir=TB is the default value to begin with, so adding it isn't really going to do anything.
That said, if I am reading your subgraph correctly, it looks like:
You have a collection of 5 record-type nodes in a cluster.
Each of those nodes have inbound edges from one or more nodes outside the cluster.
None of the nodes within the cluster have edges between them.
If that's correct, then the nodes in your subgraph have the same rank (or probably do, depending upon the rank of the nodes that connect to them). Setting rankdir=LR (or rankdir=RL) will change the orientation of that subgraph so the nodes are aligned vertically, but it will also change the alignment of the overall graph.
One way to get just those nodes to be aligned vertically is to add an invisible edge between them. For example, if you have nodes A, B, C, D and E, your cluster definition might look something like this:
digraph G {
// ...skipping stuff outside the cluster...
subgraph clusterFoo {
node [shape=record]
A [label="..."]
B [label="..."]
C [label="..."]
D [label="..."]
E [label="..."]
edge [style=invis]
A -> B -> C -> D -> E
}
}
Adding the edges will force the nodes in the subgraph to have a different rank, so the default rankdir=TB will lay out the nodes from top to bottom rather than from left to right. The style=invis attribute on these "false" edges will make them invisible.
If you want to tweak the spacing or alignment of the nodes within the cluster you might also want to play with edge attributes such as weight or minlen/attrs.html#d:minlen), or consider constraint=false on the inbound edges.
If I've misinterpreted your graph or if this doesn't help you at all, can you update your question to add a minimal example of the DOT file you are working with?
PS: On Ubuntu, you can use:
dot -Txlib graph.dot
to quickly open up a window with a rendering of the graph in graph.dot without first writing it to a file. The rendered image will even automatically update when you modify the source file.
I am working on project where i need to find a path to the nearest (of many) goal node in 2D grid (8 connections in any node: N,S,W,E,NW,NE,SW,SE). There can be walls blocking path on the way. There is no problem when it comes to find path to one goal node, but how could i find in reasonable time which goal is nearest? I don't think running A* for every goal node and getting length of every path found to compare is reasonable way, how else can it be done?
Is A* somehow capable of finding path to nearest node, or the nearest goal must be found other way and then passed to A* as only goal?
Legend:
White - walkable
Grey - walls
Blue - myself
Green - goals
Red - enemy (i am planing to keep distance from enemy at X SQM)
Yes, just set EstimatedDistanceToEnd (aka. h(x)) to the minimum estimate over all end-nodes. Then just stop the search when you hit an end-node.
A* is for informed searches where we have some data other than just goal state... According to your question it seems like there is no relevant data and we just know what our goal state is. If that is the case then you can simply apply BFS.