int main () { printf("iterative sum of squares from 1 to 10: %d\n", summation(square, 1, 10)); printf("recursive gcd of 24 and 40: %d\n", gcd(24, 40)); printf("recursive sum of squares from 1 to 10: %d\n", summation2(square, 1, 10)); printf("iterative gcd of 24 and 40: %d\n", gcd2(24, 40)); printf("tail-recursive gcd of 24 and 40: %d\n", gcd3(24, 40)); }
void CreateSchedulingConstraint(IloModel model, BoolVarMatrix X, BoolVarMatrix Y, IloNumVarArray s, IloRangeArray c){ IloEnv env = model.getEnv(); //sum[i] holds the summation //from eqn-8 for operation i IloExprArray sum(env); //The for-loop encodes all //the execution constraints for(int i = 0; i < X.getSize(); i++){ sum.add(IloExpr(env)); for(int t = 0; t < T_MAX; t++){ X[i].add(IloBoolVar(env)); sum[i] += X[i][t]; c.add( t - s[i+1] - T_MAX*(X[i][t]-1) >= 0); c.add(-t + s[i+1] - T_MAX*(X[i][t]-1) + T >= 1); } c.add(sum[i] == T); } //Resources Constraints IloExprArray summation1(env); IloExprArray summation2(env); for(int t = 0; t < T_MAX; t++){ summation1.add(IloExpr(env)); summation2.add(IloExpr(env)); for(int i = 0; i < X.getSize(); i++){ summation1[t] += X[i][t]; } for(int e = 0; e < Y.getSize(); e++){ summation2[t] += Y[e][t]; } c.add(n_r*summation1[t] + summation2[t] <= n_m*n_r); } return; }