Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | Copyright (c) 2011 Cisco and/or its affiliates. |
| 3 | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at: |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef __included_anneal_h__ |
| 18 | #define __included_anneal_h__ |
| 19 | |
| 20 | #include <vppinfra/clib.h> |
| 21 | #include <vppinfra/format.h> |
| 22 | #include <vppinfra/random.h> |
| 23 | #include <math.h> |
| 24 | |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 25 | typedef struct |
| 26 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 27 | /* Initial temperature */ |
| 28 | f64 initial_temperature; |
| 29 | |
| 30 | /* Temperature fraction at each step, 0.95 is reasonable */ |
| 31 | f64 temperature_step; |
| 32 | |
| 33 | /* Number of temperatures used */ |
| 34 | u32 number_of_temperatures; |
| 35 | |
| 36 | /* Number of configurations tried at each temperature */ |
| 37 | u32 number_of_configurations_per_temperature; |
| 38 | |
| 39 | u32 flags; |
| 40 | #define CLIB_ANNEAL_VERBOSE (1<<0) |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 41 | #define CLIB_ANNEAL_MINIMIZE (1<<1) /* mutually exclusive */ |
| 42 | #define CLIB_ANNEAL_MAXIMIZE (1<<2) /* mutually exclusive */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 43 | |
| 44 | /* Random number seed, set to ensure repeatable results */ |
| 45 | u32 random_seed; |
| 46 | |
| 47 | /* Opaque data passed to callbacks */ |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 48 | void *opaque; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 49 | |
| 50 | /* Final temperature (output) */ |
| 51 | f64 final_temperature; |
| 52 | |
| 53 | /* Final metric (output) */ |
| 54 | f64 final_metric; |
| 55 | |
| 56 | /* Suggested initial temperature (output) */ |
| 57 | f64 suggested_initial_temperature; |
| 58 | |
| 59 | |
| 60 | /*--- Callbacks ---*/ |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 61 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 62 | /* objective function to minimize */ |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 63 | f64 (*anneal_metric) (void *opaque); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 64 | |
| 65 | /* Generate a new configuration */ |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 66 | void (*anneal_new_configuration) (void *opaque); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 67 | |
| 68 | /* Restore the previous configuration */ |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 69 | void (*anneal_restore_previous_configuration) (void *opaque); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 70 | |
| 71 | /* Save best configuration found e.g at a certain temperature */ |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 72 | void (*anneal_save_best_configuration) (void *opaque); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 73 | |
| 74 | /* restore best configuration found e.g at a certain temperature */ |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 75 | void (*anneal_restore_best_configuration) (void *opaque); |
| 76 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 77 | } clib_anneal_param_t; |
| 78 | |
| 79 | void clib_anneal (clib_anneal_param_t * p); |
| 80 | |
| 81 | #endif /* __included_anneal_h__ */ |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 82 | |
| 83 | /* |
| 84 | * fd.io coding-style-patch-verification: ON |
| 85 | * |
| 86 | * Local Variables: |
| 87 | * eval: (c-set-style "gnu") |
| 88 | * End: |
| 89 | */ |