I have developed a code for my problem and it seems like it is working but when I increase the problem size, it does not output anything. in my problem I have several courses with multiple meetings each week with a condition of each course must have at least one overall in all weeks(e.g. in a 4 weeks case, atleast one meeting in 4 weeks combined).
A sample of decired out put with 4 courses and 4 weeks looks like the following:
0, 0, 2, 0,
1, 0, 0, 0,
0, 1, 0, 1,
0, 2, 0, 3,
I have written the following recursive code and it is working for small number of courses and weeks but when I increase these number it does not output anything. even for small cases sometime it does not output anything and I have to run it againg to get a result. here is my code:
//headers
#include <iostream>
//global parameters
const int NumberOfCourses = 4;
const int AvailableWeeks = 4;
double Desired[NumberOfCourses][AvailableWeeks];
//parameters deciding how many courses should we remove from schedule
//option 0:0 f2f meeting
//option 1:1 f2f meeting
//option 2:2 f2f meeting
//option 3:3 f2f meeting
const double DN_possibilites[4] = { 0.7, 0.15, 0.1, 0.05 };
double Rand;
long int OptionSelected;
double SumOfProbabiltiesSofar = 0;
double total = 0;
int c, w;
using namespace std;
void DN_generator() {
long int currSysTime = time(NULL);
srand(currSysTime);
for (int c = 0; c < NumberOfCourses; c++) {
for (int w = 0; w < AvailableWeeks; w++) {
long int currSysTime = time(NULL);
Rand = ((float)rand() / RAND_MAX);
//cout << Rand << endl;
long int OptionSelected;
double SumOfProbabiltiesSofar = 0;
for (int i = 0; i < 4; i++) {
SumOfProbabiltiesSofar += DN_possibilites[i];
if (Rand < SumOfProbabiltiesSofar) {
OptionSelected = i;
break;
}
}
if (OptionSelected == 0) {
Desired[c][w] = 0;
}
else if (OptionSelected == 1) {
Desired[c][w] = 1;
}
else if (OptionSelected == 2) {
Desired[c][w] = 2;
}
else if (OptionSelected == 3) {
Desired[c][w] = 3;
}
}
}
for (c = 0; c < NumberOfCourses; c++) {
total = 0;
for (w = 0; w < AvailableWeeks; w++) {
total += Desired[c][w];
}
if (total == 0) {
DN_generator();
}
}
}
int main(){
DN_generator();
for (c = 0; c < NumberOfCourses; c++) {
for (w = 0; w < AvailableWeeks; w++) {
cout << Desired[c][w] << ", ";
}
cout << endl;
}
return 0;
}
any help is much appreciated.