Ejemplo n.º 1
0
bool check_metrics(latin_grid square1) {
  // check whether this the best in any category.
  // return true if it is the worse than the best so far in every category
  // print it if the the square is complete and it is the best in some category
  bool is_complete = current_row == square1->size;
  int orthogonal = orthogonality_repeats(square1, temp_square2);
  int diagonal_AB = diagonal_repeats(square1, temp_square2) ;
  int diagonal_BA = diagonal_repeats(square1, temp_square2) ;
  int DE = diagonal_AB + diagonal_BA;
  if (orthogonal < best_orthogonal) {
    if (is_complete) {
      best_DE_for_A = DE;
      best_orthogonal = orthogonal;
      report2(square1, temp_square2);
    }
    return false;
  }
  if (orthogonal == best_orthogonal && DE < best_DE_for_A) {
    if (is_complete) {
      best_DE_for_A = DE;
      report2(square1, temp_square2);
    }
    return false;
  }
  return true;
}
Ejemplo n.º 2
0
int main() {
  
  verbose = true;
  
  int sequence_13A[13] = { 0, 2, 4, 8, 3, 6, 12, 11, 9, 5, 10, 7, 1 };
  int sequence_13B[13] = { 0, 8, 3, 6, 12, 11, 9, 5, 10, 7, 1, 2, 4 };
  int sequence_17A[17] = { 0, 3, 9, 10, 13, 5, 15, 11, 16, 14, 8, 7, 4, 12, 2, 6, 1 };
  int sequence_17B[17] = { 0, 10, 13, 5, 15, 11, 16, 14, 8, 7, 4, 12, 2, 6, 1, 3, 9 };
  int sequence_19A[19] = { 0, 2, 4, 8, 16, 13, 7, 14, 9, 18, 17, 15, 11, 3, 6, 12, 5, 10, 1 };
  int sequence_19B[19] = { 0, 8, 16, 13, 7, 14, 9, 18, 17, 15, 11, 3, 6, 12, 5, 10, 1, 2, 4 };
  
  latin_grid square13A = new_latin_grid(13);
  fill_in_square(sequence_13A, square13A);
  latin_grid square13B = new_latin_grid(13);
  fill_in_square(sequence_13B, square13B);
  latin_grid square17A = new_latin_grid(17);
  fill_in_square(sequence_17A, square17A);
  latin_grid square17B = new_latin_grid(17);
  fill_in_square(sequence_17B, square17B);
  latin_grid square19A = new_latin_grid(19);
  fill_in_square(sequence_19A, square19A);
  latin_grid square19B = new_latin_grid(19);
  fill_in_square(sequence_19B, square19B);
  
  report2(square13A, square13B);
  report2(square17A, square17B);
  report2(square19A, square19B);
  
  return 0;
}
Ejemplo n.º 3
0
bool check_metric(int metric, int* best, bool complete, latin_grid square1) {
  // check whether this metric is the best in this category
  // return true if it is worse in this category
  // print the squares if it is best in this category and complete
  //printf("m:%d b:%d\n", metric, *best);
  if (metric < *best) {
    if (complete) {
      *best = metric;
      report2(square1, temp_square2);
    }
    return false;
  }
  return true;
}
Ejemplo n.º 4
0
void print_success(latin_grid square) {
  if (square == square_B) {
    bool new_result = false;
    int row_repeats_A = repeat_count(diff_used_A);
    int row_repeats_B = repeat_count(diff_used_B);
    int AB_repeats = repeat_count(diff_used_diagonal_AB);
    int total_diagonal_repeats =
      AB_repeats + repeat_count(diff_used_diagonal_BA);
    if (row_repeats_A < least_row_repeats_A) {
      least_row_repeats_A = row_repeats_A;
      new_result = true;
    }
    if (row_repeats_B < least_row_repeats_B) {
      least_row_repeats_B = row_repeats_B;
      new_result = true;
    }
    if (AB_repeats < least_AB_repeats &&
        least_row_repeats_A == row_repeats_A &&
        least_row_repeats_B == row_repeats_B) {
      least_AB_repeats = AB_repeats;
      new_result = true;
    }
    if (total_diagonal_repeats < least_diagonal_repeats &&
        least_row_repeats_A == row_repeats_A &&
        least_row_repeats_B == row_repeats_B) {
      least_diagonal_repeats = total_diagonal_repeats;
      new_result = true;
    }
    
    if (verbose && new_result) {
      fill_in_square(square_A);
      fill_in_square(square_B);
      report2(square_A, square_B);
    }
    
    total_found++;
  } else {
    coord position = new_coord();
    position->row = 0;
    position->col = 1;
    backtrack(square_B, position);
  }
}
Ejemplo n.º 5
0
int
main(int argc, char **argv)
{
   IloEnv env;
   try {
      IloInt  i, j;

      IloNum      rollWidth;
      IloNumArray amount(env);
      IloNumArray size(env);

      if ( argc > 1 )
         readData(argv[1], rollWidth, size, amount);
      else
         readData("../../../examples/data/cutstock.dat",
                  rollWidth, size, amount);

      /// CUTTING-OPTIMIZATION PROBLEM ///

      IloModel cutOpt (env);

      IloObjective   RollsUsed = IloAdd(cutOpt, IloMinimize(env));
      IloRangeArray  Fill = IloAdd(cutOpt,
                                   IloRangeArray(env, amount, IloInfinity));
      IloNumVarArray Cut(env);

      IloInt nWdth = size.getSize();
      for (j = 0; j < nWdth; j++) {
         Cut.add(IloNumVar(RollsUsed(1) + Fill[j](int(rollWidth / size[j]))));
      }
      
      IloCplex cutSolver(cutOpt);

      /// PATTERN-GENERATION PROBLEM ///

      IloModel patGen (env);

      IloObjective ReducedCost = IloAdd(patGen, IloMinimize(env, 1));
      IloNumVarArray Use(env, nWdth, 0.0, IloInfinity, ILOINT);
      patGen.add(IloScalProd(size, Use) <= rollWidth);

      IloCplex patSolver(patGen);

      /// COLUMN-GENERATION PROCEDURE ///

      IloNumArray price(env, nWdth);
      IloNumArray newPatt(env, nWdth);

      /// COLUMN-GENERATION PROCEDURE ///

      for (;;) {
         /// OPTIMIZE OVER CURRENT PATTERNS ///
       
         cutSolver.solve();
         report1 (cutSolver, Cut, Fill);
       
         /// FIND AND ADD A NEW PATTERN ///
       
         for (i = 0; i < nWdth; i++) {
           price[i] = -cutSolver.getDual(Fill[i]);
         }
         ReducedCost.setLinearCoefs(Use, price);
       
         patSolver.solve();
         report2 (patSolver, Use, ReducedCost);
       
         if (patSolver.getValue(ReducedCost) > -RC_EPS) break;
       
         patSolver.getValues(newPatt, Use);
         Cut.add( IloNumVar(RollsUsed(1) + Fill(newPatt)) );
      }

      cutOpt.add(IloConversion(env, Cut, ILOINT));

      cutSolver.solve();
      cout << "Solution status: " << cutSolver.getStatus() << endl;
      report3 (cutSolver, Cut);
   }
   catch (IloException& ex) {
      cerr << "Error: " << ex << endl;
   }
   catch (...) {
      cerr << "Error" << endl;
   }

   env.end();

   return 0;
}
Ejemplo n.º 6
0
 menu()
{
 int x;
  do{
       {
	clrscr();
	design();
	t();
	textcolor(WHITE);
	gotoxy(24,3);
	cprintf("\xDB\xDB\xDB\xDB\xB2  SAM'S DEPARTMANTAL STORE  \xB2\xDB\xDB\xDB\xDB");
	gotoxy(3,4);
	cprintf("--------------------------------------------------------------------------");
	gotoxy(35,5);
	cprintf("MAIN MENU");
	gotoxy(26,8);
	cprintf(" 1  -   INFORMATION ABOUT PRODUCTS            ");
	gotoxy(26,9);
	cprintf(" 2  -   ENTER  PURCHASE  RECORDS            ");
	gotoxy(26,10);
	cprintf(" 3  -   ENTER PRODUCTS TO BE SALE           ");
	gotoxy(26,11);
	cprintf(" 4  -   SEARCH FOR RECORD                     ");
	gotoxy(26,12);
	cprintf(" 5  -   DELETE RECORD FROM STORE DATABASE     ");
	gotoxy(26,13);
	cprintf(" 6  -   VIEW SALES , PURCHASE & PROFIT REPORT ");
	gotoxy(26,14);
	cprintf(" 7  -   PRINT RECORDS                         ");
	gotoxy(26,15);
	cprintf(" 8  -   BAR  GRAPH OF QUANTITY / PROFIT       ");
	gotoxy(26,16);
	cprintf(" 9  -   RETRIEVE INFORMATION         ");
	gotoxy(26,17);
	cprintf(" H  -   HELP                                  ");
	gotoxy(26,18);
	cprintf(" E  -   EXIT                                  ");
	gotoxy(26,23);
	cprintf("ENTER YOUR CHOICE :: ");
	gotoxy(47,23);
	x=toupper(getch());
	switch(x)
	{
	case '1':
	infor();
	break;

	case '2':
	entry();
	break;

	case '3':
	edit();
	break;

	case '4':
	search();
	break;

	case '5':
	del();
	break;

	case '6':
	report2();
	break;

	case '7':
	print();
	break;

	case 'h': case'H':
	help();
	break;

	case'8':
	graph1();
	break;

	case '9':
	display();
	break;

	case 'e': case 'E':
	exit(0);
	break;

	default:
	clrscr();
	design();
	gotoxy(17,12);
	printf("\a\xDB\xB2  WRONG ENTRY : PRESS ANY KEY AND TRY AGAIN");
	getche();
	}
      }
    }while((x!='e')||(x!='E'));
return x;
}