Macro to find N shortest edges in model

It is possible to easily identify the shortest edge in a dbs file, but in some cases it may be desirable to identify more than one short edge simultaneously. Using the new query commands in Gambit 2, it is possible to create a macro to find N edges shorter than a prescribed arc length.
You can also modify the previous macro to turn on the labels of the short edges, making them easier to locate. Just replace the following block of commands in the original macro with the block that appears below it. (You may need to first view Resolution 2 to get the text of the original macro).

Original Macro:

if COND ($count .le. $max_edges)
$edge[$count] = $x1[$p]
$count = $count + 1

Replace the above lines with:

if COND ($count .le. $max_edges)
window modify edge $x1[$p] label nolower
$edge[$count] = $x1[$p]
$count = $count + 1

To use the macro, it should be loaded in to a gambit session as a
journal file, using the edit/run option. When it appears in the Edit
Journal panel, the value of the parameter $short should be changed to
the minimum edge length, i.e. it is desired to identify edges shorter
than this, and the value of the parameter $max_edges should be changed
to what ever value is desired. Then all lines in the macro should be
selected and Auto should be clicked. After the commands have been
executed (nothing has happened yet; the macro has just been loaded), to
run the macro type the following in the Command box at the bottom of the
gambit GUI:

macrorun name "find_short_edges"

To see the names of the edges that are shorter than the value given to
$short, open the parameters panel (Edit > Parameters), click "edge" in
the Edit Parameters panel and then click Values in the lower right hand
part of the panel. A new panel will open, displaying the names of the
short edges.

Text of journal file is below:
macro start "find_short_edges"
/ Gambit macro to find shortest edges in model
/ This macro loops through all edges in
/ a model and finds up to N edges with arclength
/ less than a prescribed minimum value
/ Usage:
/ Load the file macrotest.txt from the Run Journal
/ menu. Select Edit/Run and load the file.
/ In the Edit/Run Journal panel, change values
/ of parameters if desired (see below), select
/ all commands and select Auto. Once the journal is loaded
/ click in the Command box in the lower left corner of
/ the gambit GUI and type the command
/ macrorun name "find_short_edges". After the
/ macro has executed, to see a list of the short edges
/ open the Edit Parameters panel, click on edge so that
/ it is highlighted in black, then click on Values near
/ the lower right corner of the panel.
/ Parameter Definitions
/ $short: Find all edges shorter than value assigned to $short
/ $max_edges: Find up to $max_edges shorter than $short
/ $x1: Array storing all edges in model
/ $num_edge: Total number of edges in model
/ $edge_length: Arclength of edge currently under consideration
/ $edge: Array storing up to $max_edges shorter than $short
$short = 1.1
$max_edges = 10
$x1 = LISTENTITY(t_ed)
$num_edge = PARAMSIZE("x1")
/ $count,$p and $edge_length must be
/ initialized prior to their use in the
/ do loop and if statements
$count = 1
$p = 1
$edge_length = $short + 1
/ $edge must be declared explicitly
declare $edge[$max_edges]
do para "$p" init 1 cond ($p .le. $num_edge)
$edge_length = ARCLEN($x1[$p])
if COND ($edge_length .le. $short)
if COND ($count .le. $max_edges)
$edge[$count] = $x1[$p]
$count = $count + 1
macro end

Show Form
No comments yet. Be the first to add a comment!