Skip to content

generate command

Paweł Waligóra edited this page Dec 15, 2023 · 23 revisions

Generate

Call

program call with generate command:

./knapsack-solver.exe generate [directory / file path] [optional arguments]

Functionality

Behaviour of generate command is highly dependent on presence of an opional argument: -batch.

If -batch argument is not present: generate creates one .json file specified by [directory / file path]

If -batch argument is present: generate creates a folder specified by [directory / file path], populates it with batch-info.json file and subfolder problems/. Generates packaged_problem_X.json files within problems/ subfolder each containing an instance of knapsack problem. Such folder is called a batch folder.

Arguments

[directory / file path] - full path defining either batch folder or packaged_problem.json file depending on -batch presence.

Optional Arguments:

  • -file [file name] - full path to .json file containing generation settings
  • -batch [amount] - use batch generate. [amount] - a number of problems to generate.
  • -isize [instance size]
  • -subk [sub knapsacks]
  • -maxks [max knapsack size]
  • -maxv [max item value]
  • -maxw [max item weight]
  • -cd [connection density]
  • -structure [structure to find], where [structure to find] can be one of the following:
    • path - (default)
    • cycle
    • tree
    • connected-graph
    • ignore-connections
  • -weight-treatment [weight treatment], where [weight treatment] can be one of the following:
    • respect-all - (default)
    • ignore-all
    • respect-first-only
    • set-all-to-1

Example Output

for following program call:

./knapsack-solver.exe generate ./packaged_problem_0.json -isize 18 -subk 1 -maxks 25 -maxv 10 -maxw 10 -cd 0.1 -structure path

Program would respond by reating a file named packaged_problem_0.json in programs directory with following contents:

{
    "cycle_guarantee": "no-guarantees",
    "directed": true,
    "items": [
        {
            "connections": [
                13
            ],
            "value": 6,
            "weights": [
                3
            ]
        },
        {
            "connections": [
                0,
                2,
                3,
                4,
                16
            ],
            "value": 5,
            "weights": [
                7
            ]
        },
        {
            "connections": [
                0,
                1,
                3,
                15,
                17
            ],
            "value": 7,
            "weights": [
                4
            ]
        },
        {
            "connections": [
                1,
                6,
                17
            ],
            "value": 2,
            "weights": [
                9
            ]
        },
        {
            "connections": [
                0,
                5
            ],
            "value": 9,
            "weights": [
                8
            ]
        },
        {
            "connections": [
                9
            ],
            "value": 7,
            "weights": [
                4
            ]
        },
        {
            "connections": [],
            "value": 9,
            "weights": [
                4
            ]
        },
        {
            "connections": [
                0
            ],
            "value": 2,
            "weights": [
                8
            ]
        },
        {
            "connections": [
                7,
                12
            ],
            "value": 4,
            "weights": [
                9
            ]
        },
        {
            "connections": [
                4,
                5,
                7,
                10,
                17
            ],
            "value": 9,
            "weights": [
                9
            ]
        },
        {
            "connections": [
                12
            ],
            "value": 0,
            "weights": [
                1
            ]
        },
        {
            "connections": [
                3
            ],
            "value": 0,
            "weights": [
                8
            ]
        },
        {
            "connections": [
                2
            ],
            "value": 5,
            "weights": [
                5
            ]
        },
        {
            "connections": [
                2,
                4,
                11
            ],
            "value": 8,
            "weights": [
                2
            ]
        },
        {
            "connections": [],
            "value": 1,
            "weights": [
                0
            ]
        },
        {
            "connections": [
                10,
                17
            ],
            "value": 7,
            "weights": [
                7
            ]
        },
        {
            "connections": [
                7,
                8
            ],
            "value": 5,
            "weights": [
                9
            ]
        },
        {
            "connections": [],
            "value": 0,
            "weights": [
                4
            ]
        }
    ],
    "knapsack_sizes": [
        18
    ],
    "optimum": -1,
    "structure_to_find": "path",
    "weight_treatment": "respect-all"
}