Using NeverGrad in Python for speed/weight optimization

40 Views Asked by At

I have the following optimization problem. I have a Python code that is able to determine the power needed for a car when the user gives the speed and weight for several points during a trip. This code is divided into four scripts that each have their own purpose and the final result is a dataframe with the results for all points in the trip. This code is inside a function that can be called directly. So basically the code looks like this:

enter image description here

Now I want to take it further by using an optimization to determine the combination of speed and weight that results in the lowest power. So parameters to be variated are the speed and weight combinations and the goal is to have the lowest power.

First I created a list of the combination (simple example given here):

enter image description here

Hence: 64 different combinations for which the best combination has to be found.

After some reading, I think the best approach is to use the Python package 'NeverGrad', since it provides a gradient-free optimization, which seems to be easy and usable in my case.

The problem is the implementation. I have looked at the examples, but I cannot figure out how to get it to work. I was thinking at first that the basic example (https://facebookresearch.github.io/nevergrad/optimization.html) would be sufficient, but it seems that I'm missing something.

Does someone has experience with this and is able to share thoughts on how to do this? Basically what I need is a code like this:

import nevergrad as ng

def func(list_combinations):
    
    # Go into the four scripts and return the dataframe with all results
    
    # Get the power of the dataframe. The optimization must return the entire dataframe row with the lowest power value
    
    return # result

# My list of combinations
list_combinations

optimizer = ng.optimizers.NGOpt(parametrization=2, budget=100)
recommendation = optimizer.minimize(func)
0

There are 0 best solutions below