Repast / repast.simphony

Git repository for Repast Simphony development
repast.github.io
90 stars 21 forks source link

Invalid Border Rule Error #35

Closed AChammas closed 3 years ago

AChammas commented 3 years ago

Hi, I ran the java tutorial once and didn't have any issue. I then tried to write my own code, and when I try to set my context as the data loader, I get the following set of errors for space and grid:

ERROR [AWT-EventQueue-0] 16:06:57,107 repast.simphony.dataLoader.engine.GridProjectionBuilder - Unable to build Grid 'grid': invalid border rule java.lang.IllegalArgumentException: Invalid border rule ERROR [AWT-EventQueue-0] 16:06:57,107 repast.simphony.dataLoader.engine.GridProjectionBuilder - Unable to build Grid 'grid': too few dimensions specified java.lang.IllegalArgumentException: Too few dimensions specified

I had deleted the tutorial so I wrote everything again and I got the same error.

Would it be possible to know how to fix it?

Thanks,

Antoine

jozik commented 3 years ago

If you just want to re-import the tutorial model, you could delete what you have in your workspace and re-import it. If you need to download the sample models again, here's the link for those.

To better understand the error's cause, you'd need to post, e.g., the ContextBuilder you've created.

AChammas commented 3 years ago

Hi,

Thanks for the link I will look into the examples and compare them with what I've written. Here is the jzombies context builder I wrote that is throwing the errors mentioned above:

package jzombies;

import repast.simphony.context.Context; import repast.simphony.context.space.continuous.ContinuousSpaceFactory; import repast.simphony.context.space.continuous.ContinuousSpaceFactoryFinder; import repast.simphony.context.space.grid.GridFactory; import repast.simphony.context.space.grid.GridFactoryFinder; import repast.simphony.dataLoader.ContextBuilder; import repast.simphony.random.RandomHelper; import repast.simphony.space.continuous.ContinuousSpace; import repast.simphony.space.continuous.NdPoint; import repast.simphony.space.continuous.RandomCartesianAdder; import repast.simphony.space.grid.Grid; import repast.simphony.space.grid.GridBuilderParameters; import repast.simphony.space.grid.SimpleGridAdder; import repast.simphony.space.grid.WrapAroundBorders;

public class JZombiesBuilder implements ContextBuilder {

@Override
public Context build(Context<Object> context) {

    context.setId("jzombies");

    ContinuousSpaceFactory spaceFactory = 
            ContinuousSpaceFactoryFinder.createContinuousSpaceFactory(null);
    ContinuousSpace<Object> space =
            spaceFactory.createContinuousSpace("space", context,
                    new RandomCartesianAdder<Object>(), 
                    new repast.simphony.space.continuous.WrapAroundBorders(),
                    50, 50);

    GridFactory gridFactory = GridFactoryFinder.createGridFactory(null);
    Grid<Object> grid = gridFactory.createGrid("grid", context,
            new GridBuilderParameters<Object>(new WrapAroundBorders(),
                    new SimpleGridAdder<Object>(),
                    true, 50, 50));

    int zombieCount = 5;
    for(int i = 0; i<zombieCount;i++) {
        context.add(new Zombie(space, grid));
    }
    int humanCount = 100;
    for (int i = 0; i < humanCount; i++) {
        int energy = RandomHelper.nextIntFromTo(4, 10);
        context.add(new Human(space, grid, energy));    
    }
    for(Object obj:context) {
        NdPoint pt = space.getLocation(obj);
        grid.moveTo(obj, (int)pt.getX(), (int)pt.getY());
    }

    return context;
}

}

AChammas commented 3 years ago

I tested out the JZombies_Demo model and it worked out fine, the issue I have seems to be because of the DataLoader.. the builders aren't appearing as options when I choose set data loaders even in the JZombies_Demo model. The error I get is after choosing context.xml as the data source type and it appears that way even with the JZombies_Demo model if chose context.xml when setting my data loader.. could this be due to the illegal reflective access warning?

Thanks for your help.

AChammas commented 3 years ago

Ah nevermind, I found myerror, I was setting context.xml when I should have used custom context builder.