problem.rst.txt 968 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. 2. Problem instance
  2. ===================
  3. In this tutorial, we introduce the way of using `macop` and running your algorithm quickly.
  4. 2.1 Problem definition
  5. ~~~~~~~~~~~~~~~~~~~~~~
  6. .. image:: ../_static/documentation/knapsack_problem.png
  7. :width: 300 px
  8. :align: center
  9. 2.2 Problem implementation
  10. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  11. Hence, we define our problem in Python:
  12. - value of each component of knapsack
  13. - weight associated to each of these components (objects)
  14. .. code:: python
  15. """
  16. imports part
  17. """
  18. import random
  19. """
  20. Problem definition
  21. """
  22. random.seed(42)
  23. elements_score = [ random.randint(1, 20) for _ in range(30) ] # value of each object
  24. elements_weight = [ random.randint(5, 25) for _ in range(30) ] # weight of each object
  25. First of all we need to define the kind of solution which best represent the problem. As example, we use the well known knapsack problem using 30 objects (solution size of 30).