-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProblemGenerator.cpp
69 lines (59 loc) · 2.19 KB
/
ProblemGenerator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "ProblemGenerator.h"
#include "ProblemInstance.h"
#include "Object.h"
#include <iostream>
using namespace std;
ProblemInstance *ProblemGenerator::generateProblem() {
ProblemInstance* problemInstance = new ProblemInstance();
problemInstance -> capacity = getCapacity();
problemInstance -> quantity = getObjectsQuantity();
generateObjectsList(problemInstance);
return problemInstance;
}
int ProblemGenerator::getCapacity() {
int capacity;
cout<<"Type knapsack capacity: ";
cin>>capacity;
return capacity;
}
int ProblemGenerator::getObjectsQuantity() {
int quantity;
cout<<"Type objects quantity: ";
cin>>quantity;
return quantity;
}
void ProblemGenerator::generateObjectsList(ProblemInstance *problemInstance) {
string answer;
bool isDrawEnabled = false;
int objectsLeft = problemInstance->quantity;
while(1) {
cout << "Do You want to draw objects' weights and values? [Y/n] ";
cin >> answer;
if (answer == "Y" || answer == "y" || answer == "Yes" || answer == "yes"){ isDrawEnabled = true; break; }
else if (answer == "N" || answer == "n" || answer == "No" || answer == "no"){ isDrawEnabled = false; break; }
}
while(objectsLeft){
if(isDrawEnabled){
Object* object = new Object(objectsLeft);
objectsLeft--;
problemInstance->objectsList.push_front(object);
}
else{
int weigth, value;
cout<<"Object "<<objectsLeft<<":\n";
cout<<"Type weight: ";
cin>>weigth;
cout<<"Type value: ";
cin>>value;
Object* object = new Object(objectsLeft,value,weigth);
objectsLeft--;
problemInstance->objectsList.push_front(object);
// while(1) {
// cout << "Do You want to draw remaining objects' weights and values? [Y/n] ";
// cin >> answer;
// if (answer == "Y" || answer == "y" || answer == "Yes" || answer == "yes"){ isDrawEnabled = true; break; }
// else if (answer == "N" || answer == "n" || answer == "No" || answer == "no"){ isDrawEnabled = false; break; }
// }
}
}
}