Commits

Michał Odnous  committed 57d47fd

Support for specifying domain bounds.

  • Participants
  • Parent commits 64495ef

Comments (0)

Files changed (2)

File examples/rosenbrock/evaluator.py

         [100., 100.],
     ]
 
-    def __init__(self, local_mode=False, addresses=None, ports=None):
+    def __init__(self, local_mode=False, addresses=None, ports=None, 
+            max_x=None, min_x=None, max_y=None, min_y=None):
+        # Store constraints or fall back to defaults.
+        self.min_constr = [
+            min_x if min_x is not None else self.CONSTRAINTS[0][0],
+            min_y if min_y is not None else self.CONSTRAINTS[0][1],
+        ]
+        self.max_constr = [
+            max_x if max_x is not None else self.CONSTRAINTS[1][0],
+            max_y if max_y is not None else self.CONSTRAINTS[1][1],
+        ]
+
         # Set up communication.
         # ZMQ socket listening for commands.
         self.listener = ctx.socket(zmq.PULL)
         u"Handle request for optimization options."
         return MessageType.RESP_OPTIONS, {
             "num_params": self.NUM_PARAMS,
-            "min_constr": self.CONSTRAINTS[0],
-            "max_constr": self.CONSTRAINTS[1],
+            "min_constr": self.min_constr,
+            "max_constr": self.max_constr,
         }
 
     def handle_evaluation(self, data):

File examples/rosenbrock/run.py

         dest="network_publish", type=str, default="5559",
         help=u"Listening port for task result broadcasting")
 
+    # Rosenbrock params.
+    parser.add_argument("-max-x", metavar="<number>", dest="max_x", type=float,
+        help=u"Upper limit on X axis.")
+    parser.add_argument("-min-x", metavar="<number>", dest="min_x", type=float,
+        help=u"Lower limit on X axis.")
+    parser.add_argument("-max-y", metavar="<number>", dest="max_y", type=float,
+        help=u"Upper limit on Y axis.")
+    parser.add_argument("-min-y", metavar="<number>", dest="min_y", type=float,
+        help=u"Lower limit on Y axis.")
+
     # Parse execution arguments.
     args = parser.parse_args()
 
     # Initialize evaluator and listen for commands.
     e = RosenbrockEvaluator(local_mode=args.local_mode,
         addresses=[args.local_pull, args.local_publish],
-        ports=[args.network_pull, args.network_publish])
+        ports=[args.network_pull, args.network_publish],
+        max_x=args.max_x, min_x=args.min_x,
+        max_y=args.max_y, min_y=args.min_y)
     e.run()