instance.rst 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. UBQP Problem instance generation
  2. ================================
  3. To define our quadratic assignment problem instance, we will use the available mUBQP_ multi-objective quadratic problem generator.
  4. Genration of the instance
  5. ~~~~~~~~~~~~~~~~~~~~~~~~~
  6. We will limit ourselves here to a single objective for the purposes of this example. The available file **mubqpGenerator.R**, will be used to generate the instance (using R language).
  7. .. code:: bash
  8. Rscript mubqpGenerator.R 0.8 1 100 5 42 ubqp_instance.txt
  9. The main parameters used for generating our UBQP instance are:
  10. - **ρ:** the objective correlation coefficient
  11. - **M:** the number of objective functions
  12. - **N:** the length of bit strings
  13. - **d:** the matrix density (frequency of non-zero numbers)
  14. - **s:** seed to use
  15. .. _mUBQP: http://mocobench.sourceforge.net/index.php?n=Problem.MUBQP
  16. .. _ubqp_instance.txt: https://github.com/jbuisine/macop/blob/master/examples/instances/ubqp/ubqp_instance.txt
  17. Load data instance
  18. ~~~~~~~~~~~~~~~~~~
  19. We are now going to load this instance via a Python code which will be useful to us later on:
  20. .. code:: Python
  21. qap_instance_file = 'ubqp_instance.txt'
  22. n = 100 # the instance size
  23. # load UBQP instance
  24. with open(ubqp_instance_file, 'r') as f:
  25. lines = f.readlines()
  26. # get all string floating point values of matrix
  27. Q_data = ''.join([ line.replace('\n', '') for line in lines[8:] ])
  28. # load the concatenate obtained string
  29. Q_matrix = np.fromstring(Q_data, dtype=float, sep=' ').reshape(n, n)
  30. print(f'Q_matrix {Q_matrix.shape}')
  31. .. note::
  32. As we know the size of our instance and the structure of the document (header size), it is quite quick to look for the lines related to the :math:`Q` matrix.