generate_problem.py 833 B

123456789101112131415161718192021222324252627282930
  1. import numpy as np
  2. from scipy import sparse
  3. import utils.codegen_utils as cu
  4. P = sparse.triu([[4., 1.], [1., 2.]], format='csc')
  5. q = np.ones(2)
  6. A = sparse.csc_matrix(np.array([[1., 1.], [1., 0.], [0., 1.], [0., 1.]]))
  7. l = np.array([1., 0., 0., -np.inf])
  8. u = np.array([1., 0.7, 0.7, np.inf])
  9. n = P.shape[0]
  10. m = A.shape[0]
  11. # New data
  12. q_new = np.array([2.5, 3.2])
  13. l_new = np.array([0.8, -3.4, -np.inf, 0.5])
  14. u_new = np.array([1.6, 1.0, np.inf, 0.5])
  15. # Generate problem solutions
  16. sols_data = {'x_test': np.array([0.3, 0.7]),
  17. 'y_test': np.array([-2.9, 0.0, 0.2, 0.0]),
  18. 'obj_value_test': 1.88,
  19. 'status_test': 'optimal',
  20. 'q_new': q_new,
  21. 'l_new': l_new,
  22. 'u_new': u_new}
  23. # Generate problem data
  24. cu.generate_problem_data(P, q, A, l, u, 'basic_qp', sols_data)