Menu

about generics parameter for class Problem

Help
Xie Yi
2015-06-13
2015-06-13
  • Xie Yi

    Xie Yi - 2015-06-13

    I would like to use String as the variable value type. But the V is asked to be addable. Does the addable attribute of type V have something to do with the implement of the class? Could I safely remove the restriction?

     

    Last edit: Xie Yi 2015-06-13
  • Thomas B. Léauté

    Hi Xie Yi,

    FRODO requires variable values to be addable because most DCOP problems include constraints that involve adding variables. For instance, you might have a constraint over two variables x and y that imposes that x + y < 10.

    In your case, however, if you are calling FRODO via the API using only Hypercubes, then most algorithms will not involve adding variable values. As a consequence, you can use virtually any type for variable values.

    In practice, the simplest way to have string-valued variables is to implement an AddableString class that implements Addable, but in which most of the methods do not need to be implemented. Some of the methods defined in the Addable interface or its super-interface(s) are really needed, though, such as equals(), hashCode(), externalize(), and readResolve() - although this list is not exhaustive.

    Tip: in Eclipse (if you use this IDE), you can configure your code templates such that when you create a new class that implements a given interface, all methods are created automatically for you with a method content that includes a line like the following:

    assert false : "Not yet implemented!";
    

    Then, if you call Java with asserts enabled (JVM option -ea), you will be notified whenever FRODO calls a method of your new AddableString class that you haven't implemented yet. This way, you can make sure you implement all the methods needed, but only the methods needed.

    Best,

    Thomas

     

Log in to post a comment.