MaDKit forum

Welcome All !
Please, use explicit topic names when creating new threads. Thanks.

You are not logged in.

#1 TurtleKit questions (how to) » How to get the set of patches in radius k ? » 2011-10-19 13:17:58

lois.vanhee
Replies: 0

Hello,

I would like to create a turtle that look for the most promising food spot in its spot radius. I would like to have the same operator than the NetLogo operator "in radius" to do it properly.

Unfortunately, this operator is a turtle operation. Is there another way to access it ? It can be bypassed via "getPatchVariableAt" and rewritting locally the "in radius" method. Is there a way to do it more properly ?

#2 TurtleKit wishlist and general discussion » Finality of Turtle » 2011-10-19 10:59:49

lois.vanhee
Replies: 1

Hello,

Many turtle operations (like "die") are declared as final. Such declaration can complicate further extensions of turtles.

For instance, MyTurtle, extending Turtle belongs to a group. When my turtle dies, I wish I can call "die" and have it removed from its group. As "die" is final, I cannot do that, and I have to call "myDie()" which performs desired operations and terminates by calling "die()". The programmer has now to take 2 levels of operations (one at the Turtle level one one at MyTurtle level), increasing the overall complexity of his software.

Is there a strong reason that forces Turtle operations to be final ?

Thank you

#3 TurtleKit bugs » Unknown starting bug » 2011-10-10 13:57:04

lois.vanhee
Replies: 1

Hello,

I encounter sometime a strange exception when TK starts up. I have absolutely no explaination about it.


    -----------------------------------------------------

            MadKit/Aalaadin

          by MadKit Team (c) 1997-2008

             version: 4.4.0 - Exodus

    -----------------------------------------------------

Please file bug reports on the madkit forum at http://www.madkit.org

<MadKit Kernel> : MadKit Agent microKernel @navi:1771 is up and running

Loading src/spiral/Spiral.xml
SD loaded...
SD UIManager loaded...
SD launcher loaded...
[Observer0] : activated

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException
    at javax.swing.LayoutComparator.compare(LayoutComparator.java:89)
    at java.util.Arrays.mergeSort(Arrays.java:1283)
    at java.util.Arrays.mergeSort(Arrays.java:1295)
    at java.util.Arrays.mergeSort(Arrays.java:1294)
    at java.util.Arrays.mergeSort(Arrays.java:1295)
    at java.util.Arrays.mergeSort(Arrays.java:1294)
    at java.util.Arrays.sort(Arrays.java:1223)
    at java.util.Collections.sort(Collections.java:176)
    at javax.swing.SortingFocusTraversalPolicy.enumerateAndSortCycle(SortingFocusTraversalPolicy.java:136)
    at javax.swing.SortingFocusTraversalPolicy.getComponentAfter(SortingFocusTraversalPolicy.java:261)
    at javax.swing.LayoutFocusTraversalPolicy.getComponentAfter(LayoutFocusTraversalPolicy.java:105)
    at java.awt.Component.getNextFocusCandidate(Component.java:7630)
    at java.awt.DefaultKeyboardFocusManager.doRestoreFocus(DefaultKeyboardFocusManager.java:162)
    at java.awt.DefaultKeyboardFocusManager.restoreFocus(DefaultKeyboardFocusManager.java:142)
    at java.awt.DefaultKeyboardFocusManager.restoreFocus(DefaultKeyboardFocusManager.java:125)
    at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:293)
    at java.awt.Component.dispatchEventImpl(Component.java:4499)
    at java.awt.Container.dispatchEventImpl(Container.java:2103)
    at java.awt.Window.dispatchEventImpl(Window.java:2517)
    at java.awt.Component.dispatchEvent(Component.java:4455)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:649)
    at java.awt.EventQueue.access$000(EventQueue.java:96)
    at java.awt.EventQueue$1.run(EventQueue.java:608)
    at java.awt.EventQueue$1.run(EventQueue.java:606)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:105)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:116)
    at java.awt.EventQueue$2.run(EventQueue.java:622)
    at java.awt.EventQueue$2.run(EventQueue.java:620)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:105)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:619)
    at java.awt.SequencedEvent.dispatch(SequencedEvent.java:113)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:647)
    at java.awt.EventQueue.access$000(EventQueue.java:96)
    at java.awt.EventQueue$1.run(EventQueue.java:608)
    at java.awt.EventQueue$1.run(EventQueue.java:606)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:105)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:116)
    at java.awt.EventQueue$2.run(EventQueue.java:622)
    at java.awt.EventQueue$2.run(EventQueue.java:620)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:105)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:619)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:275)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:200)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:185)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:177)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:138)
[SD launcher] : Simulation is initialized !!

[SD launcher] : Click to begin...

#4 Re: TurtleKit questions (how to) » Go-like cycle » 2011-10-10 11:06:24

Thanks to Fabien, I found the go-loop in the TurtleScheduler. Unfortunately, TurtleScheduler cannot be selected as a parameter of the application.
For now, I bypassed this issue in modifying the TK code (my personnal class, which extends TurtleScheduler is initialized instead of TurtleScheduler), but now my version differs from the official TK one. Is there a line I can change in the XML file in order to select my scheduler instead of the TK one ?

#5 TurtleKit questions (how to) » How to get the set of turtles » 2011-10-10 10:58:26

lois.vanhee
Replies: 1

Dear all,

I would like to access the turtles, in order to display some info about them in a separate panel. How can I access turtles ?
In TurtleActivator, there is a way, but this method is local and non-static. As the turtle set and the patch set are unique objects, is there a way to obtain static access to it ?

Thank you in advance for your help

#6 TurtleKit bugs » [Bug fix] Bug on Turtle.directionAngleToPoint(x,y) » 2011-10-05 09:51:38

lois.vanhee
Replies: 1

The method directionAngleToPoint(x,y) appears to be buggy when x = 0. The aim of this function seems to compute the angle between the vector (1,0) and (x,y). It is used by the TurtleKit translation of the famous NetLogo construction "heading towards".

Here is the initial code :
    private double directionAngleToPoint(double x, double y) {
        if (x == 0 && y == 0) return 0.0;
        if(x > 0)
            if(y > 0)
                return toDegrees(atan(y/x));
            else
                return 360.0 + toDegrees(atan(y/x));
        else
            return 180.0 + toDegrees(atan(y/x));
    }

If x==0, we should return "180.0 + toDegrees(atan(y/x))".
As x==0, y/x is not a number and should trigger a NaN exception. x and y are typed as doubles, so Java evaluates "y/x" as the infinity with the sign of y (if y>0, NaN otherwise). Consequently, if x==0 and y> 0 atan(y/x) is -Pi/2 but should be the opposite (and symmetrically when x==0 and y<0).

A quick solution for this bug is to replace the first "x>0" by "x>=0".

The first statement "if (x == 0 && y == 0) return 0.0" should raise an error. NetLogo do it when this case occors (because there is no angle between 2 vectors if one of those is the zero vector, more simply how to answser the question "what is the direction of the North pole ?" when stepping on the North pole).

#7 Re: TurtleKit questions (how to) » Display not refreshed » 2011-10-04 15:07:44

I would like to know more about how TK manages patches. Apparently, each observer accesses the "patchGrid". Is this object shared between every view (which would be problematic with color setting, because 2 views would have the same patch color) ?

What is the best way to access patches ? Now I do it through an Observer, so I have to multiply patch operations if I want to update multiple Observers.

#8 TurtleKit questions (how to) » Go-like cycle » 2011-10-04 15:00:04

lois.vanhee
Replies: 2

Dear all,

In NetLogo, every time the "go" button is processed, patches and turtles can be updated. I would like to be able to do the same in TK. How can I access this "go" loop in TK ?

Thank you for your help

#9 Re: TurtleKit questions (how to) » Display not refreshed » 2011-10-04 12:43:52

Ok, I will check this out. Why is it not the default function of the Viewer class ?

#10 Re: TurtleKit questions (how to) » Patch information » 2011-10-04 12:42:21

Great, this will simplify a lot my work. Thank you !

#11 TurtleKit questions (how to) » Patch information » 2011-10-03 15:42:59

lois.vanhee
Replies: 2

Dear all,

In NetLogo, we can very easily add information on patches (in basic examples, the size of the grass for instance). In TK, I tried to do the same in extending the Patch class, but it appeared to be final. My current solution consists in handling it externally (with a patch manager class) but does not appear to be very elequant.

Is there a way to do it more properly ?

Thank you for your help,

#12 TurtleKit questions (how to) » Display not refreshed » 2011-10-03 15:37:29

lois.vanhee
Replies: 5

Dear all,

I extended the Viewer class to represent turtles with triangles and patches with squares in overloading the "paintTurtle" and "paintPatch" operations. The graphics are not repainted during this operation. Consequently, when my turtles move, I add the new position (what I want to) but I let the old trace on the painting device. When a repaint is called (in changing the size of the display for instance), old traces are cleared.

Do I have to call manyally a "repaint" every round ? If so, is there a method called every round, or have I to add another device by hand to check for it ?


Thank you for your help

Board footer