Originally posted by: SystemAdmin
Hello,
The simplest way to create a list of lists in a loop with Python is to use code like the following
my_list = [0] * list_length
for i in list_length:
# your code to define new_sublist, the ith entry of my_list, goes here
my_list[i] = new_sublist
To fill in the details of the definition of new_sublist at each iteration, I would need to know how the data for your objective function is stored.
If your objective function is diagonal, you can specify just the diagonal values by passing a list of floats to the set_quadratic() method.
If your objective function is not diagonal, but it is very sparse, it may be easier to use the set_quadratic_coefficients() method. This method allows the quadratic coefficients to be set one at a time or in "triplet" format, where each coefficient is specified by
[column_index, row_index, value]
This method also
allows you to make changes to the quadratic objective without the overhead of changing the entire matrix.
Let me know if you have any further questions.
Philip Starhill
CPLEX Research Engineer
#CPLEXOptimizers#DecisionOptimization