Page 1 of 1

How to find arrrows without polarities?

Posted: Wed Nov 20, 2024 11:31 am
by kleemax
Is there a way to find arrows without polarities? In GMB workshops in order to save time, the marking of polarities may sometimes be postponed until after the workshop. Duriong that work, esp. in a messy diagram, it would be good to have a way to find arrows without polarity marking. If there is no built-in tool for this in Vensim:
a) please file this as a feature request
b) is there a way to do this in the text version of the model? My guess is that this is stored in the sketch information?

Re: How to find arrrows without polarities?

Posted: Wed Nov 20, 2024 11:38 am
by Administrator
There is no way to do this now. But we could add it under the "Edit" menu. There is already a bunch of select modes there, I can add "Arrows without a polarity marking".

Re: How to find arrrows without polarities?

Posted: Wed Nov 20, 2024 3:51 pm
by Amistra
It's a work around, but in small model segments you can see the marked and unmarked arrows with the Causes/Uses tool. Right click on the Causes/Uses tool icon to show Tool Options, and for Arrows check Polarity (you can also click Color and Width). Tree size Depth = 3 and Height = 2 gives a manageable segment size. Click OK, select a variable, and the output shows which arrows in the displayed segment have/don't have polarities.

Checking in segments could be a good GMB breakout exercise - assign views to breakout teams, and step through all the variables using Causes/Uses (but not the shadow variables) in the view until all polarities are added. The Causes/Uses window can be pushed out of the way so the view can be edited (polarities added) with the segment still visible, but you need to close and reopen to see the changed (added) polarity markings.

Re: How to find arrrows without polarities?

Posted: Thu Nov 21, 2024 7:38 am
by kleemax
Adding this option the Edit menu would be nice! Kindly let me know when it gets implemented. Thanks also for the workaround-hint with cases/uses trees. Unfortunately that won't work for me as I am using PLE plus.

Re: How to find arrrows without polarities?

Posted: Thu Nov 21, 2024 8:07 am
by Administrator
It will be in the next release (I'm not sure when that will be). Keep an eye out here and on the various social media platforms for notification.

Re: How to find arrrows without polarities?

Posted: Thu Nov 21, 2024 5:20 pm
by aliakhavan89
A workaround for this (look at the screenshots below): go to View As Text and look for the properties of variables and arrows. In the lines that start with '1' (denoting arrows), if you find the 7th element is 0, it means that the arrow doesn't have any polarities. 43 and 45 correspond to positive and negative polarities, respectively. The 3rd and 4th elements in that row show the causal direction. In this case, it says '2,1', meaning that the arrow goes from variable 2 (birth rate) to variable 1 (population). Then, you can go back to View As Sketch, find those variables, and add the polarity.

Note that modifying those numbers in View AS Text may corrupt the Vensim file.

Alternatively, you can ask an LLM to automate this process by reading the mdl file directly and printing the missing polarities. I did it for the test model very quickly but haven't tested it for larger models. Make sure you have backups of your model if you're going to run such scripts.

Screenshot 2024-11-21 at 11.50.04 AM.png
Screenshot 2024-11-21 at 11.50.04 AM.png (645.92 KiB) Viewed 5786 times
Screenshot 2024-11-21 at 11.50.35 AM.png
Screenshot 2024-11-21 at 11.50.35 AM.png (59.92 KiB) Viewed 5786 times
Screenshot 2024-11-21 at 12.17.19 PM.png
Screenshot 2024-11-21 at 12.17.19 PM.png (387.06 KiB) Viewed 5786 times
I'll share the code and the model in the next comment.

(side note: I think it should be View as Test or View as Sketch with small a for conjunction, like Export as SVG)

Re: How to find arrrows without polarities?

Posted: Thu Nov 21, 2024 5:22 pm
by aliakhavan89
here's the code and the model I tested:

Code: Select all

import csv

def find_variables_with_missing_polarities(mdl_file_path):
    variable_mapping = {}
    variables_with_missing_polarities = set()
    
    with open(mdl_file_path, 'r', encoding='utf-8') as file:
        reader = csv.reader(file)
        lines = list(reader)
    
    # First pass: build variable index to name mapping
    for line in lines:
        if not line:
            continue
        if line[0].strip() == '10':
            try:
                var_index = line[1].strip()
                var_name = line[2].strip()
                variable_mapping[var_index] = var_name
            except IndexError:
                continue  # Skip malformed lines
    
    # Second pass: find arrows with missing polarities
    for line in lines:
        if not line:
            continue
        if line[0].strip() == '1':
            # Ensure there are enough elements
            if len(line) < 7:
                continue
            try:
                polarity = line[6].strip()
                if polarity == '0':
                    source_index = line[2].strip()
                    target_index = line[3].strip()
                    source_name = variable_mapping.get(source_index, f"Unknown({source_index})")
                    target_name = variable_mapping.get(target_index, f"Unknown({target_index})")
                    variables_with_missing_polarities.add(source_name)
                    variables_with_missing_polarities.add(target_name)
            except IndexError:
                continue  # Skip malformed lines
    
    if variables_with_missing_polarities:
        print("Variables with missing polarities on their arrows:")
        for var in sorted(variables_with_missing_polarities):
            print(f"- {var}")
    else:
        print("No variables with missing polarities found.")

# Example usage:
# Replace 'test.mdl' with the path to your mdl file
find_variables_with_missing_polarities('/Users/Ali/Desktop/test.mdl')