示例#1
0
uint8_t* CBC_PDF417Writer::Encode(const CFX_WideString& contents,
                                  int32_t& outWidth,
                                  int32_t& outHeight,
                                  int32_t& e) {
  CBC_PDF417 encoder;
  int32_t col = (m_Width / m_ModuleWidth - 69) / 17;
  int32_t row = m_Height / (m_ModuleWidth * 20);
  if (row >= 3 && row <= 90 && col >= 1 && col <= 30) {
    encoder.setDimensions(col, col, row, row);
  } else if (col >= 1 && col <= 30) {
    encoder.setDimensions(col, col, 90, 3);
  } else if (row >= 3 && row <= 90) {
    encoder.setDimensions(30, 1, row, row);
  }
  encoder.generateBarcodeLogic(contents, m_iCorrectLevel, e);
  BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
  int32_t lineThickness = 2;
  int32_t aspectRatio = 4;
  CBC_BarcodeMatrix* barcodeMatrix = encoder.getBarcodeMatrix();
  CFX_ByteArray originalScale;
  originalScale.Copy(barcodeMatrix->getScaledMatrix(
      lineThickness, aspectRatio * lineThickness));
  int32_t width = outWidth;
  int32_t height = outHeight;
  outWidth = barcodeMatrix->getWidth();
  outHeight = barcodeMatrix->getHeight();
  bool rotated = false;
  if ((height > width) ^ (outWidth < outHeight)) {
    rotateArray(originalScale, outHeight, outWidth);
    rotated = true;
    int32_t temp = outHeight;
    outHeight = outWidth;
    outWidth = temp;
  }
  int32_t scaleX = width / outWidth;
  int32_t scaleY = height / outHeight;
  int32_t scale;
  if (scaleX < scaleY) {
    scale = scaleX;
  } else {
    scale = scaleY;
  }
  if (scale > 1) {
    originalScale.RemoveAll();
    originalScale.Copy(barcodeMatrix->getScaledMatrix(
        scale * lineThickness, scale * aspectRatio * lineThickness));
    if (rotated) {
      rotateArray(originalScale, outHeight, outWidth);
      int32_t temp = outHeight;
      outHeight = outWidth;
      outWidth = temp;
    }
  }
  uint8_t* result = FX_Alloc2D(uint8_t, outHeight, outWidth);
  FXSYS_memcpy(result, originalScale.GetData(), outHeight * outWidth);
  return result;
}
int main()
{
  int array[100],i,direction,len,rot,element;
  printf("\nEnter size of array:");
  scanf_s("%d",&len);
  printf("\nEnter Array:\n");
  for(i=0;i<len;i++)
        scanf_s("%d",&array[i],sizeof(array));

  printf("Enter no of rotations:");
  scanf_s("%d",&rot);

  printf("\nEnter clockwise(0) or anticlockwise(1):");
  scanf_s("%d",&direction);

  printf("\nEnter search element:");
  scanf_s("%d",&element);

  if(rot%len==0){                        //if number of rotations is multiple of array length then array will be as it is given
       display(array,len);
       searchElement(array,0,len-1,element);
  }
  else
       rotateArray(array,len,rot,direction,element);
  _getch;
}
示例#3
0
pfs::Frame* rotateFrame( pfs::Frame* inpfsframe, bool clock_wise ) {

	pfs::DOMIO pfsio;
	bool clockwise = clock_wise;
	int xSize = -1;
	int ySize = -1;
	
	pfs::Frame *rotatedFrame = NULL;
// 	pfs::Channel *R, *G, *B;
// 	inpfsframe->getRGBChannels( R, G, B );
// 	assert( R!=NULL && G!=NULL && B!=NULL );

	xSize = inpfsframe->getHeight();
	ySize = inpfsframe->getWidth();
	rotatedFrame = pfsio.createFrame( xSize, ySize );
	
	pfs::ChannelIterator *it = inpfsframe->getChannels();
	while( it->hasNext() ) {
		pfs::Channel *originalCh = it->getNext();
		pfs::Channel *newCh = rotatedFrame->createChannel( originalCh->getName() );
		
		rotateArray( originalCh, newCh, clockwise );
	}
	
	pfs::copyTags( inpfsframe, rotatedFrame );
	return rotatedFrame;
}
int main()
{
    std::cout << "vector:\n";
    rotateVector();
    std::cout << "\narray:\n";
    rotateArray();
    return 0;
}
示例#5
0
//EFFECTS: Outputs a Sudoku Puzzle with "count" values filled in
void generateSudokuPuzzle(int count) {
	char sudokustring[] = "123567894456189237789234156214356789365798412897412365532641978648973521971825643";
	int usedArray[9][9];
	int countArray[9] = {0,0,0,0,0,0,0,0,0} ;
	int i, j, cursor1, cursor2, counter;
	int **sudokuarray;

	memset(usedArray, 0, 9 * sizeof(usedArray[0]));

	sudokuarray = decodeSudokuString(sudokustring);
	if (VERBOSE) printSudokuPuzzle(sudokuarray);

	for (i = 0; i < (rand() % count); i ++) {

		if (VERBOSE) printf("Swapping rows.\n");
		swapRows(&sudokuarray);
		if (VERBOSE) printSudokuPuzzle(sudokuarray);
		if (VERBOSE) printf("Rotating array.\n");
		sudokuarray = rotateArray(sudokuarray);
		if (VERBOSE) printSudokuPuzzle(sudokuarray);
	}

	for(i=0; i< (81-count); i++) {

		do {
			cursor1 = rand() % 9;
			cursor2 = rand() % 9;
		} while (usedArray[cursor1][cursor2]);

		usedArray[cursor1][cursor2] = 1;

		if (countArray[sudokuarray[cursor1][cursor2]-1] >= 8) {
			if (VERBOSE) printf("%d has already been taken away 8 times\n", sudokuarray[cursor1][cursor2]);
			i--;
		}
		else {
			countArray[sudokuarray[cursor1][cursor2]-1] = countArray[sudokuarray[cursor1][cursor2]-1] + 1;
			if (VERBOSE) printf("%d has already been taken away %d times\n", sudokuarray[cursor1][cursor2], countArray[sudokuarray[cursor1][cursor2]-1]);
			sudokuarray[cursor1][cursor2]=0;
		}
	}

	printSudokuPuzzle(sudokuarray);

	for (i = 0, counter = 0; i < 9; i++)
		for (j = 0; j < 9; j++, counter++) {
			sudokustring[counter] = (char) (((int) '0') + sudokuarray[i][j]);
	}

	printf("Testing if sudoku puzzle is correct\n");
	printf("Result: %s\n", (testSudokuString(sudokustring) == 1) ? "Correct" : "Incorrect" );

	for(i = 0; i < 9; i++)
		free(sudokuarray[i]);
	free(sudokuarray);
}
示例#6
0
文件: q7.c 项目: kanishk7/Code_
int main()
{
//	return main2();
	size = 10;
	int i;
	int a[size];
	generateSortedArr(a,size);
//	printArr(a,size);	
	rotateArray(a,size,4);
	printArr(a,size);
	scanf("%d",&i);
	printf("Index is = %d.\n",value(a,size,i));
	return 0;
}
示例#7
0
int main(int argc, const char * argv[])
{
    int array[] = {1, 2, 3, 4, 5};
    std::cout << "Rotation of (1,2,3,4,5) by 2" << std::endl;
    
    if(rotateArray(array, 5, 2)) {
        for(int i = 0; i < 5; ++i) {
            std::cout << array[i] << " ";
        }
        std::cout << std::endl;
    } else {
        std::cerr << "Memory allocation failure!" << std::endl;
        return -1;
    }
    
    return 0;
}
    void DifferentialEvolution::calculateNextGeneration(
                                     std::vector<Candidate>& population,
                                     const CostFunction& costFunction) const {

        std::vector<Candidate> mirrorPopulation;
        std::vector<Candidate> oldPopulation = population;

        switch (configuration().strategy) {

          case Rand1Standard: {
              std::random_shuffle(population.begin(), population.end());
              std::vector<Candidate> shuffledPop1 = population;
              std::random_shuffle(population.begin(), population.end());
              std::vector<Candidate> shuffledPop2 = population;
              std::random_shuffle(population.begin(), population.end());
              mirrorPopulation = shuffledPop1;

              for (Size popIter = 0; popIter < population.size(); popIter++) {
                  population[popIter].values = population[popIter].values
                      + configuration().stepsizeWeight
                      * (shuffledPop1[popIter].values - shuffledPop2[popIter].values);
              }
          }
            break;

          case BestMemberWithJitter: {
              std::random_shuffle(population.begin(), population.end());
              std::vector<Candidate> shuffledPop1 = population;
              std::random_shuffle(population.begin(), population.end());
              Array jitter(population[0].values.size(), 0.0);

              for (Size popIter = 0; popIter < population.size(); popIter++) {
                  for (Size jitterIter = 0; jitterIter < jitter.size(); jitterIter++) {
                      jitter[jitterIter] = rng_.nextReal();
                  }
                  population[popIter].values = bestMemberEver_.values
                      + (shuffledPop1[popIter].values - population[popIter].values)
                      * (0.0001 * jitter + configuration().stepsizeWeight);
              }
              mirrorPopulation = std::vector<Candidate>(population.size(),
                                                        bestMemberEver_);
          }
            break;

          case CurrentToBest2Diffs: {
              std::random_shuffle(population.begin(), population.end());
              std::vector<Candidate> shuffledPop1 = population;
              std::random_shuffle(population.begin(), population.end());

              for (Size popIter = 0; popIter < population.size(); popIter++) {
                  population[popIter].values = oldPopulation[popIter].values
                      + configuration().stepsizeWeight
                      * (bestMemberEver_.values - oldPopulation[popIter].values)
                      + configuration().stepsizeWeight
                      * (population[popIter].values - shuffledPop1[popIter].values);
              }
              mirrorPopulation = shuffledPop1;
          }
            break;

          case Rand1DiffWithPerVectorDither: {
              std::random_shuffle(population.begin(), population.end());
              std::vector<Candidate> shuffledPop1 = population;
              std::random_shuffle(population.begin(), population.end());
              std::vector<Candidate> shuffledPop2 = population;
              std::random_shuffle(population.begin(), population.end());
              mirrorPopulation = shuffledPop1;
              Array FWeight = Array(population.front().values.size(), 0.0);
              for (Size fwIter = 0; fwIter < FWeight.size(); fwIter++)
                  FWeight[fwIter] = (1.0 - configuration().stepsizeWeight)
                      * rng_.nextReal() + configuration().stepsizeWeight;
              for (Size popIter = 0; popIter < population.size(); popIter++) {
                  population[popIter].values = population[popIter].values
                      + FWeight * (shuffledPop1[popIter].values - shuffledPop2[popIter].values);
              }
          }
            break;

          case Rand1DiffWithDither: {
              std::random_shuffle(population.begin(), population.end());
              std::vector<Candidate> shuffledPop1 = population;
              std::random_shuffle(population.begin(), population.end());
              std::vector<Candidate> shuffledPop2 = population;
              std::random_shuffle(population.begin(), population.end());
              mirrorPopulation = shuffledPop1;
              Real FWeight = (1.0 - configuration().stepsizeWeight) * rng_.nextReal()
                  + configuration().stepsizeWeight;
              for (Size popIter = 0; popIter < population.size(); popIter++) {
                  population[popIter].values = population[popIter].values
                      + FWeight * (shuffledPop1[popIter].values - shuffledPop2[popIter].values);
              }
          }
            break;

          case EitherOrWithOptimalRecombination: {
              std::random_shuffle(population.begin(), population.end());
              std::vector<Candidate> shuffledPop1 = population;
              std::random_shuffle(population.begin(), population.end());
              std::vector<Candidate> shuffledPop2 = population;
              std::random_shuffle(population.begin(), population.end());
              mirrorPopulation = shuffledPop1;
              Real probFWeight = 0.5;
              if (rng_.nextReal() < probFWeight) {
                  for (Size popIter = 0; popIter < population.size(); popIter++) {
                      population[popIter].values = oldPopulation[popIter].values
                          + configuration().stepsizeWeight
                          * (shuffledPop1[popIter].values - shuffledPop2[popIter].values);
                  }
              } else {
                  Real K = 0.5 * (configuration().stepsizeWeight + 1); // invariant with respect to probFWeight used
                  for (Size popIter = 0; popIter < population.size(); popIter++) {
                      population[popIter].values = oldPopulation[popIter].values
                          + K
                          * (shuffledPop1[popIter].values - shuffledPop2[popIter].values
                             - 2.0 * population[popIter].values);
                  }
              }
          }
            break;

          case Rand1SelfadaptiveWithRotation: {
              std::random_shuffle(population.begin(), population.end());
              std::vector<Candidate> shuffledPop1 = population;
              std::random_shuffle(population.begin(), population.end());
              std::vector<Candidate> shuffledPop2 = population;
              std::random_shuffle(population.begin(), population.end());
              mirrorPopulation = shuffledPop1;

              adaptSizeWeights();

              for (Size popIter = 0; popIter < population.size(); popIter++) {
                  if (rng_.nextReal() < 0.1){
                      population[popIter].values = rotateArray(bestMemberEver_.values);
                  }else {
                      population[popIter].values = bestMemberEver_.values
                          + currGenSizeWeights_[popIter]
                          * (shuffledPop1[popIter].values - shuffledPop2[popIter].values);
                  }
              }
          }
            break;

          default:
            QL_FAIL("Unknown strategy ("
                    << Integer(configuration().strategy) << ")");
        }
        // in order to avoid unnecessary copying we use the same population object for mutants
        crossover(oldPopulation, population, population, mirrorPopulation,
                  costFunction);
    }