davidrmiller / biosim4

Biological evolution simulator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Repeated sensorVal message

venzen opened this issue · comments

Great video and good idea to make the code open source .

Successfully compiled from the instructions in the README file using the docker image.

For the initial hundred or so generations of most sims I run, this message repeats verbosely:

sensorVal=-2147483648 for genetic similarity fwd

Do most users experience this or is it perhaps due to a wayward parameter ?

I'm not seeing repeat messages other than this particular value and genetic similarity "fwd".

I received a report of this from another person, so there must be a bug in genomeSimilarity() in src/genome-compare.cpp. The configuration parameter genomeComparisonMethod in biosim4.ini determines which of three different comparison methods are used. The default is the function hammingDistanceBits(). For now, one way to proceed is to compile the program without that sensor by moving the enumerant GENETIC_SIM_FWD in src/sensors-actions.h.

Thank you for the reply.

I tried each of the 3 comparison methods and they all yielded the same repeating error message of "sensorVal=-2147483648". So, as you say, the bug must be somewhere in the calculation of sensorVal for GENETIC_SIM_FWD.

I am doing debugging starting from here in getSensor.cpp:

case Sensor::GENETIC_SIM_FWD:
    {
        // Return minimum sensor value if nobody is alive in the forward adjacent location,
        // else returns a similarity match in the sensor range 0.0..1.0
        Coord loc2 = loc + lastMoveDir;
        if (grid.isInBounds(loc2) && grid.isOccupiedAt(loc2)) {
            const Indiv &indiv2 = peeps.getIndiv(loc2);
            if (indiv2.alive) {
                sensorVal = genomeSimilarity(genome, indiv2.genome); // 0.0..1.0
                std::cout << "SIM_FWD: sensorVal=" << (int)sensorVal << std::endl;
            }
        }
        break;
    }

[EDIT - related: this _FWD bug is probably the reason why I see predominantly diagonal mode of agent travel in my sim videos.]

@venzen, I noticed that sensorVal is not initialized when allocated in getSensor() and can return with an undefined value from getSensor(). I modified src/getSensor.cpp to fix that. Can you test if that helps?

Initializing sensorVal fixes it! I've run several quick sims and a larger resource-heavy sim without the issue recurring. Let's close PR #21.

ezoic increase your site revenue