예제 #1
0
void CBC_PDF417::generateBarcodeLogic(CFX_WideString msg,
                                      int32_t errorCorrectionLevel,
                                      int32_t& e) {
  int32_t errorCorrectionCodeWords =
      CBC_PDF417ErrorCorrection::getErrorCorrectionCodewordCount(
          errorCorrectionLevel, e);
  if (e != BCExceptionNO)
    return;
  CFX_WideString highLevel =
      CBC_PDF417HighLevelEncoder::encodeHighLevel(msg, m_compaction, e);
  if (e != BCExceptionNO)
    return;
  int32_t sourceCodeWords = highLevel.GetLength();
  CFX_ArrayTemplate<int32_t>* dimension =
      determineDimensions(sourceCodeWords, errorCorrectionCodeWords, e);
  if (e != BCExceptionNO)
    return;
  int32_t cols = dimension->GetAt(0);
  int32_t rows = dimension->GetAt(1);
  delete dimension;
  int32_t pad = getNumberOfPadCodewords(sourceCodeWords,
                                        errorCorrectionCodeWords, cols, rows);
  if (sourceCodeWords + errorCorrectionCodeWords + 1 > 929) {
    e = BCExceptionEncodedMessageContainsTooManyCodeWords;
    return;
  }
  int32_t n = sourceCodeWords + pad + 1;
  CFX_WideString sb;
  sb += (FX_WCHAR)n;
  sb += highLevel;
  for (int32_t i = 0; i < pad; i++) {
    sb += (FX_WCHAR)900;
  }
  CFX_WideString dataCodewords(sb);
  CFX_WideString ec = CBC_PDF417ErrorCorrection::generateErrorCorrection(
      dataCodewords, errorCorrectionLevel, e);
  if (e != BCExceptionNO)
    return;
  CFX_WideString fullCodewords = dataCodewords + ec;
  m_barcodeMatrix = pdfium::MakeUnique<CBC_BarcodeMatrix>(rows, cols);
  encodeLowLevel(fullCodewords, cols, rows, errorCorrectionLevel,
                 m_barcodeMatrix.get());
}
returnValue OptimizationAlgorithmBase::init(	UserInteraction* _userIteraction
												)
{
    // EXTRACT INFORMATION PACKED IN THE DATA WRAPPER OCP:
    // ---------------------------------------------------
    Objective             *objective           ;
    DifferentialEquation **differentialEquation;
    Constraint            *constraint          ;

	Grid unionGrid;
	
	if ( extractOCPdata(	&objective,&differentialEquation,&constraint,
							unionGrid 
							) != SUCCESSFUL_RETURN )
		return ACADOERROR(RET_OPTALG_INIT_FAILED);

    // REFORMULATE THE OBJECTIVE IF NECESSARY:
    // ---------------------------------------

	if ( setupObjective(	objective,differentialEquation,constraint,
							unionGrid 
							) != SUCCESSFUL_RETURN )
		return ACADOERROR(RET_OPTALG_INIT_FAILED);

    // REFORMULATE THE CONSTRAINT IF NECESSARY:
    // ----------------------------------------

	if ( setupDifferentialEquation(	objective,differentialEquation,constraint,
									unionGrid 
									) != SUCCESSFUL_RETURN )
		return ACADOERROR(RET_OPTALG_INIT_FAILED);

    // DISCRETIZE THE DIFFERENTIAL EQUATION IF NECESSARY:
    // --------------------------------------------------

    DynamicDiscretization* dynamicDiscretization = 0;

	if ( setupDynamicDiscretization(	_userIteraction,
										objective,differentialEquation,constraint,
										unionGrid,
										&dynamicDiscretization
										) != SUCCESSFUL_RETURN )
		return ACADOERROR(RET_OPTALG_INIT_FAILED);

    // SETUP OF THE NLP SOLVER:
    // ------------------------
    if ( allocateNlpSolver( objective,dynamicDiscretization,constraint ) != SUCCESSFUL_RETURN )
		return ACADOERROR(RET_OPTALG_INIT_FAILED);
	
    // DETERMINE THE DIMENSIONS OF THE OPTIMIZATION VARIABLES:
    // -------------------------------------------------------

    uint nx  = 0;
    uint nxa = 0;
    uint np  = 0;
    uint nu  = 0;
    uint nw  = 0;

	if ( determineDimensions( objective,differentialEquation,constraint, nx,nxa,np,nu,nw ) != SUCCESSFUL_RETURN )
	{
		if( differentialEquation  != 0 ) delete differentialEquation[0];

		if( objective             != 0 ) delete   objective            ;
		if( differentialEquation  != 0 ) delete[] differentialEquation ;
		if( constraint            != 0 ) delete   constraint           ;
		if( dynamicDiscretization != 0 ) delete   dynamicDiscretization;

		return ACADOERROR(RET_OPTALG_INIT_FAILED);
	}
	
	if ( initializeOCPiterate( constraint,unionGrid,nx,nxa,np,nu,nw ) != SUCCESSFUL_RETURN )
	{
		if( differentialEquation != 0 ) delete differentialEquation[0];

		if( objective             != 0 ) delete   objective            ;
		if( differentialEquation  != 0 ) delete[] differentialEquation ;
		if( constraint            != 0 ) delete   constraint           ;
		if( dynamicDiscretization != 0 ) delete   dynamicDiscretization;

		return ACADOERROR(RET_OPTALG_INIT_FAILED);
	}

    // ELIMINATE EQUALITY BOUNDS: ??
    // --------------------------

    // changes the dimensions again !


    // DEFINE MULTIPLE SHOOTING NOTES
    // OR COLLOCATION NOTES IF REQUESTED:
    // ----------------------------------

       // ADAPT INITIALIZATION OF X AND XA ?

       if( iter.p  != 0 ) iter.p ->disableAutoInit();
       if( iter.u  != 0 ) iter.u ->disableAutoInit();
       if( iter.w  != 0 ) iter.w ->disableAutoInit();


    // (COLLOCATION NOT IMPLEMENTED YET)

// 	printf("before!!!\n");
// 	iter.print();

    // INITIALIZE THE NLP-ALGORITHM:
    // -----------------------------
	if ( initializeNlpSolver( iter ) != SUCCESSFUL_RETURN )
		return ACADOERROR( RET_OPTALG_INIT_FAILED );

// 	printf("after!!!\n");
// 	iter.print();
	
    // GIVE THE TEMPORARY MEMORY FREE:
    // -------------------------------
    if( differentialEquation != 0 ) delete differentialEquation[0];

    if( objective             != 0 ) delete   objective            ;
    if( differentialEquation  != 0 ) delete[] differentialEquation ;
    if( constraint            != 0 ) delete   constraint           ;
    if( dynamicDiscretization != 0 ) delete   dynamicDiscretization;

    return SUCCESSFUL_RETURN;
}