You are here: start » overswarm » protocoldef

Back

Protocol definition

Swarm protocols are defined within an .OSW file which can be compiled to generate C++/Java/… code. Each OSW file contains the description of the behavior of all the swarm agents (ants) that implement the protocol.

Syntax

PROTOCOL := protocol <string name> '{' IMPORT+ ANT* '}'
IMPORT := import (for <string output>)? '{' SUBSTITUTIONS* '}'
SUBSTITUTION := <string method> as <string function> ','
ANT := ant <string name> '{' IMPORT+ BEHAVIOR? '}'
BEHAVIOR := behavior '{' <code> '}
'

Example

/* Comments are written this way */
protocol "BlatAnt" {

    /* This is a global import part, shared among all ants */
    import {
        "MyAlgorithm::happyMethod" as "happyfunction",
        "BinboBongo::bango" as "bango"
    }

    ant "PingPong" {
        
        /* This is a local import part */
        import for "oversim" {
            "MyAlgorithm::sadMethod" as "sadfunction"
        }
        
        /* This is a local import part */
        import for "java" {
            "MyAlgorithm::sadMethod" as "sadfunction"
        }

        behavior {
            (virtual $target)
            (while 1 (begin
            (var source (migrate $target))
            (happyfunction "hello" [1,2,3])
            (migrate source)
            (sadfunction "blabla")))
        }
    }


    ant "PingPongMad" {
        
        /* This is a local import part */
        import {
            "MyAlgorithm::strangeMethod" as "strangefunction"
        }

        behavior {
            (virtual $target)
            (while 1 (begin
            (var source (migrate $target))
            (happyfunction "hello" [1,2,3])
            (migrate source)
            (strangefunction "blabla")))
        }
    }

    ant "Taco" {

     /* This is a local import part */
        import {
            "MyAlgorithm::strangeMethod" as "strangefunction"
        }

    }


    ant "Loco" {

        behavior {
            (virtual $target)
            (while 1 (begin
            (var source (migrate $target))
            (happyfunction "hello" [1,2,3])
            (migrate source)
            (strangefunction "blabla")))
        }

    }

}
overswarm/protocoldef.txt · Last modified: 2011/01/19 09:15 by attila
Kleine Websites, die ein Wiki als CMS verwenden.de