Changes between Version 20 and Version 21 of Documentation/Howto/OptimizeExternalApplications


Ignore:
Timestamp:
09/22/10 17:32:24 (9 years ago)
Author:
abeham
Comment:

changed to reflect new library version

Legend:

Unmodified
Added
Removed
Modified
  • Documentation/Howto/OptimizeExternalApplications

    v20 v21  
    4646=== Providing an evaluation service ===
    4747
    48 The following class diagram displays the classes and interfaces present in the java service framework. There is an abstract base class `Channel` on the one hand which provides methods for sending and receiving messages and several concrete implementations and on the other hand an abstract base class `Service` that provides the concrete `PollService` and `PushService`. Each Channel has a corresponding factory which implements `IChannelFactory`.
    49 
    50 [[Image(ExternalEvaluationServiceCD.png)]]
    51 
    52 In the source you will also find some test applications that provide very simple examples of how to use the service framework. They do not really evaluate a solution, but return a random number in the interval [0;1) for every received solution.
    53 
    54 [[Image(ExternalEvaluationServiceTestCD.png)]]
    55 
     48Attached to this wiki page you can find a java library that enables a quick connection with HeuristicLab over a TCP/IP connection. In this library there is an abstract base class `Channel` on the one hand which provides methods for sending and receiving messages and several concrete implementations and on the other hand an abstract base class `Service` that provides the concrete `PollService` and `PushService`. A `Listener` listens for connections and opens several channels out of which the service will receive solutions and send back qualities. As a user of the library you will prepare an `IListenerFactory` and hand this to your service instance. Then, depending on the type of service, you can get solutions out of it and push the qualities back. It is quite easy.
     49
     50Similarly a C# port of this library has also been added, which is handy when your application cannot be compiled to a dll and called directly from your C# problem plugin.
     51
     52In the following code sample you may find some test applications that provide very simple examples of how to use the service framework. They do not really evaluate a solution, but return a random number in the interval [0;1) for every received solution.
    5653
    5754==== Usage examples ====
    5855
    59 Here is the java code for the `RandomStreamingPollEvaluator`
     56Here is the java code for the `RandomSocketPollEvaluator`
    6057
    6158{{{#!java
    62 public class RandomStreamingPollEvaluator {
     59public class RandomSocketPollEvaluator {
    6360
    6461        public static void main(String[] args) {
    65                 StreamChannelFactory factory = new StreamChannelFactory(System.in, System.out);
     62                ServerSocketListenerFactory factory = new ServerSocketListenerFactory(8842);
    6663                PollService service = new PollService(factory, 1);
    6764                service.start();
     
    7067                while (true) {
    7168                        SolutionMessage msg = service.getSolution();
    72                         // parse the message and retrieve the variables there
    7369                        try {
    7470                                service.sendQuality(msg, random.nextDouble());
    7571                        } catch (IOException e) {
    76                                 break;
     72                                e.printStackTrace();
    7773                        }
    7874                }
    79                
    80                 service.stop();
    8175        }
    8276}
     
    9387                main.run();
    9488                System.out.println("Service is running, terminate by pressing <Return> or <Enter>.");
    95                 System.console().readLine();
     89                System.console().readLine(); // note: you may not always have a console
    9690                main.terminate();
    9791        }
    9892       
    9993        private void run() {
    100                 ServerSocketChannelFactory factory = new ServerSocketChannelFactory(8843);
     94                ServerSocketListenerFactory factory = new ServerSocketListenerFactory(8842);
    10195                service = new PushService(factory, 1, new RandomEvaluator());
    10296                service.start();