Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/tools/ExternalEvaluation/Java/ExtendedExternalApplication/src/com/heuristiclab/problems/externalevaluation/repetitionsextension/RandomSocketPollEvaluator.java @ 15014

Last change on this file since 15014 was 15014, checked in by pfleck, 7 years ago

Added code and tools for the ExternalEvaluationProblem. (e.g. Java-side evaluation)

File size: 1.3 KB
Line 
1package com.heuristiclab.problems.externalevaluation.repetitionsextension;
2
3import java.io.IOException;
4import java.util.*;
5import com.heuristiclab.problems.externalevaluation.*;
6import com.heuristiclab.problems.externalevaluation.ExternalEvaluationMessages.*;
7import com.heuristiclab.problems.externalevaluation.repetitionsextension.RepetitionsQualityMessage.RepetitionsResponse;
8
9public class RandomSocketPollEvaluator {
10
11  public static void main(String[] args) {
12    ServerSocketListenerFactory factory = new ServerSocketListenerFactory(8842);
13    PollService service = new PollService(factory, 1);
14    service.start();
15   
16    Random random = new Random();
17    while (true) {
18      SolutionMessage msg = service.getSolution();
19      double quality = 0;
20     
21      // replace the line below to calculate the quality
22      quality = random.nextDouble();
23      // for the simple purpose here it's just a random number
24      // now we want to populate the extension fields before we send the message back
25      QualityMessage.Builder qualityMessage =
26          service.prepareQualityMessage(msg, quality)
27          .setExtension(RepetitionsResponse.repetitions, 1);
28     
29      try {
30        service.sendQualityMessage(msg, qualityMessage.build());
31      } catch (IOException e) {
32        e.printStackTrace();
33      }
34    }
35  }
36}
Note: See TracBrowser for help on using the repository browser.