Esempio n. 1
0
/*
	用户窗口初始化
*/
MainWindow::MainWindow(QWidget *parent)
	: QMainWindow(parent)
{
	//去除标题栏、窗口置顶
	//setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
	setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
	//设置窗口大小
	
	//背景透明
	setAttribute(Qt::WA_TranslucentBackground, true);

	//播放音乐 加载音乐路径
	LoadMusic();

	//定时器设置
	TimeStart();

	//当前动作
	nowAction = 1;

	//加载图像
	image.load("image/database");
	//changeAction();

	//窗口开始位置
	resize(image.width(), image.height());
	QDesktopWidget* desktop = QApplication::desktop();
	move((desktop->width() - this->width()), 0);
}
Esempio n. 2
0
void Newton::Make_bMat(InputData& inputData,
		       Solutions& currentPt,
		       WorkVariables& work,
		       ComputeTime& com)
{
  TimeStart(START3);
  if (bMat_type == SPARSE){
    // set sparse_bMat zero 
    for (int iter=0 ; iter < sparse_bMat.NonZeroCount;++iter) {
      sparse_bMat.sp_ele[iter] = 0.0;
    }
    compute_bMat_sparse_SDP(inputData,currentPt,work,com);
    //   compute_bMat_sparse_SOCP(inputData,currentPt,work,com);
    compute_bMat_sparse_LP(inputData,currentPt,work,com);
  } else {
    bMat.setZero();
    compute_bMat_dense_SDP(inputData,currentPt,work,com);
    //    compute_bMat_dense_SOCP(inputData,currentPt,work,com);
    compute_bMat_dense_LP(inputData,currentPt,work,com);
  }
  // rMessage("bMat =  ");
  // bMat.display();
  // sparse_bMat.display();
  TimeEnd(END3);
  com.makebMat += TimeCal(START3,END3);
}
Esempio n. 3
0
void Newton::compute_DxMat(Solutions& currentPt,
			   WorkVariables& work,
			   ComputeTime& com)
{
  TimeStart(START_DX);
  // work.DLS1 = dX dZ Z^{-1}
  Jal::ns_jordan_triple_product(work.DLS1,currentPt.xMat,DzMat,
				currentPt.invzMat,work.DLS2);
  // dX = R Z^{-1} - dX dZ Z^{-1}
  Lal::let(DxMat,'=',r_zinvMat,'+',work.DLS1,&DMONE);
  TimeEnd(END_DX);
  TimeStart(START_SYMM);
  Lal::getSymmetrize(DxMat);
  TimeEnd(END_SYMM);
  // rMessage("DxMat =  ");
  // DxMat.display();
  com.makedX += TimeCal(START_DX,END_DX);
  com.symmetriseDx += TimeCal(START_SYMM,END_SYMM);
}
Esempio n. 4
0
bool Newton::compute_DyVec(Newton::WHICH_DIRECTION direction,
			   InputData& inputData,
			   Solutions& currentPt,
			   WorkVariables& work,
			   ComputeTime& com)
{
  if (direction == PREDICTOR) {
    TimeStart(START3_2);
    
    if (bMat_type == SPARSE){
      bool ret = Lal::getCholesky(sparse_bMat,diagonalIndex);
      if (ret == SDPA_FAILURE) {
	return SDPA_FAILURE;
      }
    } else {
      bool ret = Lal::choleskyFactorWithAdjust(bMat);
      if (ret == SDPA_FAILURE) {
	return SDPA_FAILURE;
      }
    }
    // rMessage("Cholesky of bMat =  ");
    // bMat.display();
    // sparse_bMat.display();
    TimeEnd(END3_2);
    com.choleskybMat += TimeCal(START3_2,END3_2);
  }
  // bMat is already cholesky factorized.


  TimeStart(START4);
  if (bMat_type == SPARSE){
    permuteVec(gVec,work.DV1);
    Lal::let(work.DV2,'=',sparse_bMat,'/',work.DV1);
    reverse_permuteVec(work.DV2,DyVec);
  } else {
    Lal::let(DyVec,'=',bMat,'/',gVec);
  }
  TimeEnd(END4);
  com.solve += TimeCal(START4,END4);
  // rMessage("DyVec =  ");
  // DyVec.display();
  return SDPA_SUCCESS;
}
Esempio n. 5
0
bool Newton::Mehrotra(Newton::WHICH_DIRECTION direction,
		      InputData& inputData,
		      Solutions& currentPt,
		      Residuals& currentRes,
		      AverageComplementarity& mu,
		      DirectionParameter& beta,
		      Switch& reduction,
		      Phase& phase,
		      WorkVariables& work,
		      ComputeTime& com)
{
  //   rMessage("xMat, yVec, zMat =  ");
  //   currentPt.xMat.display();
  //   currentPt.yVec.display();
  //   currentPt.zMat.display();

  Make_gVec(direction, inputData, currentPt, currentRes,
	    mu, beta, phase, work, com);

  if (direction == PREDICTOR) {
    Make_bMat(inputData, currentPt, work, com);
  }

  //rMessage("gVec, bMat =  ");
  //  gVec.display();
  //  bMat.display();
  //  sparse_bMat.display();  // 
  //  display_sparse_bMat();  // with reverse ordering

  bool ret = compute_DyVec(direction, inputData, currentPt, work, com);
  if (ret == SDPA_FAILURE) {
    return SDPA_FAILURE;
  }
  //  rMessage("cholesky factorization =  ");
  //  sparse_bMat.display();

  TimeStart(START5);

  compute_DzMat(inputData, currentRes, phase, com);
  compute_DxMat(currentPt, work, com);

  TimeEnd(END5);
  com.makedXdZ += TimeCal(START5,END5);

  // rMessage("DxMat, DyVec, DzMat =  ");
  //   DxMat.display();
  //   DyVec.display();
  //   DzMat.display();

  return true;
}
Esempio n. 6
0
void Newton::compute_DzMat(InputData& inputData,
			   Residuals& currentRes,
			   Phase& phase,
			   ComputeTime& com)
{
  TimeStart(START_SUMDZ);
  inputData.multi_plusToA(DyVec, DzMat);
  Lal::let(DzMat,'=',DzMat,'*',&DMONE);
  if (phase.value == SolveInfo:: pFEAS
      || phase.value == SolveInfo::noINFO) {
    Lal::let(DzMat,'=',DzMat,'+',currentRes.dualMat);
  }
  TimeEnd(END_SUMDZ);
  com.sumDz += TimeCal(START_SUMDZ,END_SUMDZ);
}
Esempio n. 7
0
int main(void)
{
   double   d,dd;
   MICRO_TIME tim;

   TimeStart(&tim);
   int i=1;
   while(/*!kbhit()*/i<1e3)
   {
      d = microTime();
//      usleep(1E6);
      dd = microTime() - d;
      //d = dd*(dd+1.0)/(dd-1.0); 
      printf("[%d] Time in microseconds: %lf = %lf s\n",i, dd,dd/1E6);
      i++;
   }
   printf("%lf sec\n",TimeStop(&tim)/1E6);
   return(0);
}
Esempio n. 8
0
bool pinpal(char* dataFile, char* initFile, char* outFile,
	    char* paraFile, bool isInitFile, bool isInitSparse,
	    bool isDataSparse, bool isParameter,
	    Parameter::parameterType parameterType,
	    FILE* Display)
{
  TimeStart(TOTAL_TIME_START1);
  TimeStart(FILE_READ_START1);
  ComputeTime com;

  FILE* fpData      = NULL;
  FILE* fpOut       = NULL;

  if ((fpOut=fopen(outFile,"w"))==NULL) {
    rError("Cannot open out file " << outFile);
  }
  Parameter param;
  param.setDefaultParameter(parameterType);
  if (isParameter) {
    FILE* fpParameter = NULL;
    if ((fpParameter=fopen(paraFile,"r"))==NULL) {
      fprintf(Display,"Cannot open parameter file %s \n",
	      paraFile);
      exit(0);
    } else {
      param.readFile(fpParameter);
      fclose(fpParameter);
    }
  }
  
  // param.display(Display,param.infPrint);

  if ((fpData=fopen(dataFile,"r"))==NULL) {
    rError("Cannot open data file " << dataFile);
  }
  char titleAndComment[LengthOfBuffer];
  int m;
  time_t ltime;
  time( &ltime );
  fprintf(fpOut,"SDPA start at %s",ctime(&ltime));
  IO::read(fpData,fpOut,m,titleAndComment);
  fprintf(fpOut,"data      is %s\n",dataFile);
  if (paraFile) {
    fprintf(fpOut,"parameter is %s\n",paraFile);
  }
  if (initFile) {
    fprintf(fpOut,"initial   is %s\n",initFile);
  }
  fprintf(fpOut,"out       is %s\n",outFile);


#if 1 // 2007/11/28 nakata    for multi LP block

  int SDP_nBlock, SOCP_nBlock,LP_nBlock, nBlock;
  IO::read(fpData,nBlock);

  int* blockStruct          = NULL;
  IO::BlockType* blockType  = NULL;
  int* blockNumber          = NULL;
  int* SDP_blockStruct      = NULL;
  int* SOCP_blockStruct     = NULL;
  NewArray(blockStruct,int,nBlock);
  NewArray(blockType,  IO::BlockType, nBlock);
  NewArray(blockNumber,int,nBlock);
  IO::read(fpData,nBlock,blockStruct);

  SDP_nBlock  = 0;
  SOCP_nBlock = 0;
  LP_nBlock   = 0;
  for (int l=0; l<nBlock; l++){
	if (blockStruct[l] >= 2) {
	  blockType[l] = IO::btSDP;
	  blockNumber[l] = SDP_nBlock;
	  SDP_nBlock++;
	} else if (blockStruct[l] < 0) {
	  blockType[l] = IO::btLP;
	  blockStruct[l] = - blockStruct[l];
	  blockNumber[l] = LP_nBlock;
	  LP_nBlock += blockStruct[l];
	} else if (blockStruct[l] == 1) {
	  blockType[l] = IO::btLP;
	  blockNumber[l] = LP_nBlock;
	  LP_nBlock += blockStruct[l];
	} else {
	  rError("block struct");
	}
  }

  NewArray(SDP_blockStruct, int,SDP_nBlock);
  NewArray(SOCP_blockStruct,int,SOCP_nBlock);
  
  SDP_nBlock = 0;
  for (int l=0; l<nBlock; l++){
	if (blockType[l] == IO::btSDP) {
	  SDP_blockStruct[SDP_nBlock] = blockStruct[l];
	  SDP_nBlock++;
	} 
  }

  InputData inputData;
  //  rMessage("read input data: start");
  IO::read(fpData, m, SDP_nBlock, SDP_blockStruct,
	   SOCP_nBlock, SOCP_blockStruct, LP_nBlock,
	   nBlock, blockStruct, blockType, blockNumber,
	   inputData,isDataSparse);
  //  rMessage("read input data: end");
  inputData.initialize_index(SDP_nBlock,SOCP_nBlock,LP_nBlock,com);
#else 

  int SDP_nBlock, SOCP_nBlock,LP_nBlock;
  IO::read(fpData,SDP_nBlock,SOCP_nBlock,LP_nBlock);
  int* SDP_blockStruct;
  int* SOCP_blockStruct;
  NewArray(SDP_blockStruct ,int,SDP_nBlock);
  NewArray(SOCP_blockStruct,int,SOCP_nBlock);
  IO::read(fpData,SDP_nBlock,SDP_blockStruct,
	   SOCP_nBlock,SOCP_blockStruct, LP_nBlock);

  for (int l=0; l<SDP_nBlock-1; l++){
    if (SDP_blockStruct[l] < 0){
      rError("LP block must be in the last block");
    }
  }
  // muriyari nyuuryoku saseru
  if (SDP_blockStruct[SDP_nBlock-1] < 0){
    LP_nBlock = - SDP_blockStruct[SDP_nBlock-1];
    SDP_nBlock--;
  }

  InputData inputData;
  IO::read(fpData, m, SDP_nBlock, SDP_blockStruct,
	   SOCP_nBlock, SOCP_blockStruct, LP_nBlock,
	   inputData,isDataSparse);
  inputData.initialize_index(SDP_nBlock,SOCP_nBlock,LP_nBlock,com);

#endif
  fclose(fpData);
  
  // inputData.display();


#if 1
  TimeStart(FILE_CHANGE_START1);
  // if possible , change C and A to Dense
  inputData.C.changeToDense();
  for (int k=0; k<m; ++k) {
    inputData.A[k].changeToDense();
  }
  TimeEnd(FILE_CHANGE_END1);
  com.FileChange += TimeCal(FILE_CHANGE_START1,
			     FILE_CHANGE_END1);
#endif

  // rMessage("C = ");
  // inputData.C.display(Display);
  // for (int k=0; k<m; ++k) {
  //   rMessage("A["<<k<<"] = ");
  //   inputData.A[k].display(Display);
  //   }
  
  // the end of initialization of C and A

  Newton newton(m, SDP_nBlock, SDP_blockStruct,
		SOCP_nBlock, SOCP_blockStruct,	LP_nBlock);
  int nBlock2 = SDP_nBlock+SOCP_nBlock+LP_nBlock;
  // 2008/03/12 kazuhide nakata
  Chordal chordal;
  // rMessage("ordering bMat: start");
  chordal.ordering_bMat(m, nBlock2, inputData, fpOut);
  // rMessage("ordering bMat: end");
  newton.initialize_bMat(m, chordal,inputData, fpOut);
  chordal.terminate();

  //  rMessage("newton.computeFormula_SDP: start");
  newton.computeFormula_SDP(inputData,0.0,KAPPA);
  //  rMessage("newton.computeFormula_SDP: end");

  // set initial solutions.
  Solutions currentPt;
  WorkVariables work;
  DenseLinearSpace initPt_xMat;
  DenseLinearSpace initPt_zMat;

  currentPt.initialize(m, SDP_nBlock, SDP_blockStruct,
		       SOCP_nBlock, SOCP_blockStruct, LP_nBlock,
		       param.lambdaStar,com);
  work.initialize(m, SDP_nBlock, SDP_blockStruct,
		  SOCP_nBlock, SOCP_blockStruct, LP_nBlock);

  if (isInitFile) {
    FILE* fpInit = NULL;
    if ((fpInit=fopen(initFile,"r"))==NULL) {
      rError("Cannot open init file " << initFile);
    }
    IO::read(fpInit,currentPt.xMat,currentPt.yVec,currentPt.zMat,
	     SDP_nBlock,SDP_blockStruct,
	     SOCP_nBlock,SOCP_blockStruct,
	     LP_nBlock, nBlock, blockStruct,
	     blockType, blockNumber,
	     isInitSparse);
    #if 0
    rMessage("intial X = ");
    currentPt.xMat.display();
    rMessage("intial Z = ");
    currentPt.zMat.display();
    #endif
    fclose(fpInit);
    currentPt.computeInverse(work,com);

    initPt_xMat.initialize(SDP_nBlock, SDP_blockStruct,
			   SOCP_nBlock, SOCP_blockStruct, 
			   LP_nBlock);
    
    initPt_zMat.initialize(SDP_nBlock, SDP_blockStruct,
			   SOCP_nBlock, SOCP_blockStruct, 
			   LP_nBlock);
    initPt_xMat.copyFrom(currentPt.xMat);
    initPt_zMat.copyFrom(currentPt.zMat);

  }
  //  rMessage("initial xMat = "); initPt_xMat.display(Display);
  //  rMessage("initial yVec = "); currentPt.yVec.display(Display);
  //  rMessage("initial zMat = "); initPt_zMat.display(Display);
  //  rMessage("current pt = "); currentPt.display(Display);
  
  TimeEnd(FILE_READ_END1);
  com.FileRead += TimeCal(FILE_READ_START1,
			   FILE_READ_END1);
  // -------------------------------------------------------------
  // the end of file read
  // -------------------------------------------------------------
  
  Residuals initRes(m, SDP_nBlock, SDP_blockStruct,
		    SOCP_nBlock, SOCP_blockStruct,
		    LP_nBlock, inputData, currentPt);
  Residuals currentRes;
  currentRes.copyFrom(initRes);
  // rMessage("initial currentRes = ");
  // currentRes.display(Display);


  StepLength alpha;
  DirectionParameter beta(param.betaStar);
  Switch reduction(Switch::ON);
  AverageComplementarity mu(param.lambdaStar);

  // rMessage("init mu"); mu.display();

  if (isInitFile) {
    mu.initialize(currentPt);
  }

  RatioInitResCurrentRes theta(param, initRes);
  SolveInfo solveInfo(inputData, currentPt, 
			mu.initial, param.omegaStar);
  Phase phase(initRes, solveInfo, param, currentPt.nDim);

  int pIteration = 0;
  IO::printHeader(fpOut, Display);
  // -----------------------------------------------------
  // Here is MAINLOOP
  // -----------------------------------------------------

  TimeStart(MAIN_LOOP_START1);
  // explicit maxIteration for debug
  // param.maxIteration = 2;
  while (phase.updateCheck(currentRes, solveInfo, param)
	 && pIteration < param.maxIteration) {
    // rMessage(" turn hajimari " << pIteration );
    // Mehrotra's Predictor
    TimeStart(MEHROTRA_PREDICTOR_START1);
    // set variable of Mehrotra
    reduction.MehrotraPredictor(phase);
    beta.MehrotraPredictor(phase, reduction, param);

    // rMessage("reduction = "); reduction.display();
    // rMessage("phase = "); phase.display();
    // rMessage("beta.predictor.value = " << beta.value);
    // rMessage(" mu = " << mu.current);
    // rMessage("currentPt = "); currentPt.display();

    bool isSuccessCholesky;
    isSuccessCholesky = newton.Mehrotra(Newton::PREDICTOR,
					inputData, currentPt,
					currentRes,
					mu, beta, reduction,
					phase,work,com);
    if (isSuccessCholesky == false) {
      break;
    }
    // rMessage("newton predictor = "); newton.display();

    TimeEnd(MEHROTRA_PREDICTOR_END1);
    com.Predictor += TimeCal(MEHROTRA_PREDICTOR_START1,
			      MEHROTRA_PREDICTOR_END1);

    TimeStart(STEP_PRE_START1);
    alpha.MehrotraPredictor(inputData, currentPt, phase, newton,
			      work, com);
    // rMessage("alpha predictor = "); alpha.display();

    TimeStart(STEP_PRE_END1);
    com.StepPredictor += TimeCal(STEP_PRE_START1,STEP_PRE_END1);

    // rMessage("alphaStar = " << param.alphaStar);
    // Mehrotra's Corrector
    // rMessage(" Corrector ");

    TimeStart(CORRECTOR_START1);
    beta.MehrotraCorrector(phase,alpha,currentPt, newton,mu,param);

    // rMessage("beta corrector = " << beta.value);

#if 1 // 2007/08/29 kazuhide nakata
    // add stopping criteria: objValPrimal < ObjValDual
    //	if ((pIteration > 10) &&
    if (phase.value == SolveInfo::pdFEAS
	&& ( beta.value> 5.0
	     || solveInfo.objValPrimal < solveInfo.objValDual)){
      break;
    }
#endif

    newton.Mehrotra(Newton::CORRECTOR,
		    inputData, currentPt, currentRes,
		    mu, beta, reduction, phase,work,com);

    // rMessage("currentPt = "); currentPt.display();
    // rMessage("newton corrector = "); newton.display();

    TimeEnd(CORRECTOR_END1);
    com.Corrector += TimeCal(CORRECTOR_START1,
			      CORRECTOR_END1);
    TimeStart(CORRECTOR_STEP_START1);
    alpha.MehrotraCorrector(inputData, currentPt, phase,
			    reduction, newton, mu, theta,
			    work, param, com);
    // rMessage("alpha corrector = "); alpha.display();
    TimeEnd(CORRECTOR_STEP_END1);
    com.StepCorrector += TimeCal(CORRECTOR_STEP_START1,
				  CORRECTOR_STEP_END1);
    // the end of Corrector
    
    IO::printOneIteration(pIteration, mu, theta, solveInfo,
			   alpha, beta, fpOut, Display);

    if (currentPt.update(alpha,newton,work,com)==false) {
      // if step length is too short,
      // we finish algorithm
      rMessage("cannot move: step length is too short");
      //   memo by kazuhide nakata
      //   StepLength::MehrotraCorrector
      //   thetaMax*mu.initial -> thetamax*thetaMax*mu.initial
      break;
    }

    // rMessage("currentPt = "); currentPt.display();
    // rMessage("updated");

    theta.update(reduction,alpha);
    mu.update(currentPt);
    currentRes.update(m,inputData, currentPt, com);
    theta.update_exact(initRes,currentRes);

    if (isInitFile) {
      solveInfo.update(inputData, initPt_xMat, initPt_zMat, currentPt,
		       currentRes, mu, theta, param);
    } else {
      solveInfo.update(param.lambdaStar,inputData, currentPt,
		       currentRes, mu, theta, param);
    }
    // 2007/09/18 kazuhide nakata
    // print information of ObjVal, residual, gap, complementarity
    // solveInfo.check(inputData, currentPt,
    //                 currentRes, mu, theta, param);
    pIteration++;
  } // end of MAIN_LOOP

  TimeEnd(MAIN_LOOP_END1);

  com.MainLoop = TimeCal(MAIN_LOOP_START1,
			  MAIN_LOOP_END1);
  currentRes.compute(m,inputData,currentPt);
  TimeEnd(TOTAL_TIME_END1);
  
  com.TotalTime = TimeCal(TOTAL_TIME_START1,
			   TOTAL_TIME_END1);
  #if REVERSE_PRIMAL_DUAL
  phase.reverse();
  #endif
#if 1
  IO::printLastInfo(pIteration, mu, theta, solveInfo, alpha, beta,
		    currentRes, phase, currentPt, com.TotalTime,
			nBlock, blockStruct, blockType, blockNumber,
		    inputData, work, com, param, fpOut, Display);
#else
  IO::printLastInfo(pIteration, mu, theta, solveInfo, alpha, beta,
		    currentRes, phase, currentPt, com.TotalTime,
		    inputData, work, com, param, fpOut, Display);
#endif
  // com.display(fpOut);

  DeleteArray(SDP_blockStruct);
  DeleteArray(blockStruct);
  DeleteArray(blockType);
  DeleteArray(blockNumber);
  
  fprintf(Display,   "  main loop time = %.6f\n",com.MainLoop);
  fprintf(fpOut,   "    main loop time = %.6f\n",com.MainLoop);
  fprintf(Display,   "      total time = %.6f\n",com.TotalTime);
  fprintf(fpOut,   "        total time = %.6f\n",com.TotalTime);
  #if 0
  fprintf(Display,   "file  check time = %.6f\n",com.FileCheck);
  fprintf(fpOut,   "  file  check time = %.6f\n",com.FileCheck);
  fprintf(Display,   "file change time = %.6f\n",com.FileChange);
  fprintf(fpOut,   "  file change time = %.6f\n",com.FileChange);
  #endif
  fprintf(Display,   "file   read time = %.6f\n",com.FileRead);
  fprintf(fpOut,   "  file   read time = %.6f\n",com.FileRead);
  fclose(fpOut);


#if 0
  rMessage("memory release");
  currentRes.terminate();
  initRes.terminate();
  currentPt.terminate();
  initPt_xMat.terminate();
  initPt_zMat.terminate();
  newton.terminate();
  work.terminate();
  inputData.terminate();
  com.~ComputeTime();
  param.~Parameter();
  alpha.~StepLength();
  beta.~DirectionParameter();
  reduction.~Switch();
  mu.~AverageComplementarity();
  theta.~RatioInitResCurrentRes();
  solveInfo.~SolveInfo();
  phase.~Phase();
#endif

  return true;
}
Esempio n. 9
0
void Newton::compute_bMat_dense_SDP(InputData& inputData,
                                    Solutions& currentPt,
                                    WorkVariables& work,
                                    ComputeTime& com)
{
  int m = currentPt.mDim;
  int SDP_nBlock = inputData.SDP_nBlock;

  for (int l=0; l<SDP_nBlock; ++l) {
    DenseMatrix& xMat = currentPt.xMat.SDP_block[l];
    DenseMatrix& invzMat = currentPt.invzMat.SDP_block[l];
    DenseMatrix& work1 = work.DLS1.SDP_block[l];
    DenseMatrix& work2 = work.DLS2.SDP_block[l];

    for (int k1=0; k1<inputData.SDP_nConstraint[l]; k1++) {
      int i = inputData.SDP_constraint[l][k1];
      int ib = inputData.SDP_blockIndex[l][k1];
      int inz = inputData.A[i].SDP_sp_block[ib].NonZeroEffect;
      SparseMatrix& Ai = inputData.A[i].SDP_sp_block[ib];

      FormulaType formula = useFormula[i*SDP_nBlock + l];
      // ---------------------------------------------------
      // formula = F3; // this is force change
      // ---------------------------------------------------
      TimeStart(B_NDIAG_START1);
      TimeStart(B_NDIAG_START2);

      bool hasF2Gcal = false;
      if (formula==F1) {
	Lal::let(work1,'=',Ai,'*',invzMat);
	Lal::let(work2,'=',xMat,'*',work1);
      } else if (formula==F2) {
	Lal::let(work1,'=',Ai,'*',invzMat);
	hasF2Gcal = false;
	// Lal::let(gMat.ele[l],'=',xMat.ele[l],'*',fMat.ele[l]);
      }
      TimeEnd(B_NDIAG_END2);
      com.B_PRE += TimeCal(B_NDIAG_START2,B_NDIAG_END2);

      for (int k2=0; k2<inputData.SDP_nConstraint[l]; k2++) {
	int j = inputData.SDP_constraint[l][k2];
	int jb = inputData.SDP_blockIndex[l][k2];
	int jnz = inputData.A[j].SDP_sp_block[jb].NonZeroEffect;
	SparseMatrix& Aj = inputData.A[j].SDP_sp_block[jb];
          
	// Select the formula A[i] or the formula A[j].
	// Use formula that has more NonZeroEffects than others.
	// We must calculate i==j.
          
	if ((inz < jnz) || ( (inz == jnz) && (i<j))) {
	  continue;
	}

	double value;
	switch (formula) {
	case F1:
	  // rMessage("calF1");
	  calF1(value,work2,Aj);
	  break;
	case F2:
	  // rMessage("calF2 ");
	  calF2(value,work1,work2,xMat,Aj,hasF2Gcal);
	  // calF1(value2,gMat.ele[l],A[j].ele[l]);
	  // rMessage("calF2:  " << (value-value2));
	  break;
	case F3:
	  // rMessage("calF3");
	  calF3(value,work1,work2,xMat,invzMat,Ai,Aj);
	  break;
	} // end of switch
	if (i!=j) {
	  bMat.de_ele[i+m*j] += value;
	  bMat.de_ele[j+m*i] += value;
	} else {
	  bMat.de_ele[i+m*i] += value;
	}
      } // end of 'for (int j)'

      TimeEnd(B_NDIAG_END1);
      double t = TimeCal(B_NDIAG_START1,B_NDIAG_END1);
      switch (formula) {
      case F1: com.B_F1 += t; break;
      case F2: com.B_F2 += t; break;
      case F3: com.B_F3 += t; break;
      }
    } // end of 'for (int i)'
  } // end of 'for (int l)'
}
Esempio n. 10
0
void Newton::Make_gVec(Newton::WHICH_DIRECTION direction,
		       InputData& inputData,
		       Solutions& currentPt,
		       Residuals& currentRes,
		       AverageComplementarity& mu,
		       DirectionParameter& beta,
		       Phase& phase,
		       WorkVariables& work,
		       ComputeTime& com)
{
  TimeStart(START1);
  // rMessage("mu = " << mu.current);
  // rMessage("beta = " << beta.value);
  compute_rMat(direction,mu,beta,currentPt,work);

  TimeEnd(END1);

  com.makerMat += TimeCal(START1,END1);

  TimeStart(START2);
  TimeStart(START_GVEC_MUL);

  // work.DLS1 = R Z^{-1} - X D Z^{-1} = r_zinv - X D Z^{-1}
  if (phase.value == SolveInfo:: pFEAS
      || phase.value == SolveInfo::noINFO) {

    if (direction == CORRECTOR) {
      // x_rd_zinvMat is computed in PREDICTOR step
      Lal::let(work.DLS1,'=',r_zinvMat,'+',x_rd_zinvMat,&DMONE);
    } else {
      // currentPt is infeasilbe, that is the residual
      // dualMat is not 0.
      //      x_rd_zinvMat = X D Z^{-1}
      Jal::ns_jordan_triple_product(x_rd_zinvMat,currentPt.xMat,
				    currentRes.dualMat,currentPt.invzMat,
				    work.DLS2);
      Lal::let(work.DLS1,'=',r_zinvMat,'+',x_rd_zinvMat,&DMONE);
    } // if (direction == CORRECTOR)

  } else {
    // dualMat == 0
    work.DLS1.copyFrom(r_zinvMat);
  }
  
  //  rMessage("work.DLS1");
  //  work.DLS1.display();

  TimeEnd(END_GVEC_MUL);
  com.makegVecMul += TimeCal(START_GVEC_MUL,END_GVEC_MUL);
    
  inputData.multi_InnerProductToA(work.DLS1,gVec);
  Lal::let(gVec,'=',gVec,'*',&DMONE);
  // rMessage("gVec =  ");
  // gVec.display();

  #if 0
  if (phase.value == SolveInfo:: dFEAS
      || phase.value == SolveInfo::noINFO) {
  #endif
    Lal::let(gVec,'=',gVec,'+',currentRes.primalVec);
  #if 0
  }
  #endif
  
  TimeEnd(END2);
  com.makegVec += TimeCal(START2,END2);
}
Esempio n. 11
0
void Newton::compute_bMat_sparse_SDP(InputData& inputData,
				     Solutions& currentPt,
				     WorkVariables& work,
				     ComputeTime& com)
{
  TimeStart(B_NDIAG_START1);
  TimeStart(B_NDIAG_START2);

  for (int l=0; l<SDP_nBlock; ++l) {
    DenseMatrix& xMat = currentPt.xMat.SDP_block[l];
    DenseMatrix& invzMat = currentPt.invzMat.SDP_block[l];
    DenseMatrix& work1 = work.DLS1.SDP_block[l];
    DenseMatrix& work2 = work.DLS2.SDP_block[l];
    int previous_i = -1;
    
    for (int iter = 0; iter < SDP_number[l]; iter++){
      //      TimeStart(B_NDIAG_START1);
      int i = SDP_constraint1[l][iter];
      int ib = SDP_blockIndex1[l][iter];
      SparseMatrix& Ai = inputData.A[i].SDP_sp_block[ib];
      FormulaType formula = useFormula[i*SDP_nBlock + l];
      bool hasF2Gcal;
      
      if (i != previous_i){
	// ---------------------------------------------------
	// formula = F3; // this is force change
	// ---------------------------------------------------
	TimeStart(B_NDIAG_START2);
	
	hasF2Gcal = false;
	if (formula==F1) {
	  Lal::let(work1,'=',Ai,'*',invzMat);
	  Lal::let(work2,'=',xMat,'*',work1);
	} else if (formula==F2) {
	  Lal::let(work1,'=',Ai,'*',invzMat);
	  hasF2Gcal = false;
	  // Lal::let(gMat.ele[l],'=',xMat.ele[l],'*',fMat.ele[l]);
	}
	TimeEnd(B_NDIAG_END2);
	com.B_PRE += TimeCal(B_NDIAG_START2,B_NDIAG_END2);
      }
      
      int j = SDP_constraint2[l][iter];
      int jb = SDP_blockIndex2[l][iter];
      SparseMatrix& Aj = inputData.A[j].SDP_sp_block[jb];
      
      double value;
      switch (formula) {
      case F1:
	// rMessage("calF1");
	calF1(value,work2,Aj);
	break;
      case F2:
	// rMessage("calF2 ");
	calF2(value,work1,work2,xMat,Aj,hasF2Gcal);
	// calF1(value2,gMat.ele[l],A[j].ele[l]);
	// rMessage("calF2:  " << (value-value2));
	break;
      case F3:
	// rMessage("calF3");
	calF3(value,work1,work2,xMat,invzMat,Ai,Aj);
	break;
      } // end of switch
      sparse_bMat.sp_ele[SDP_location_sparse_bMat[l][iter]] += value;
      previous_i = i;
    } // end of 'for (int index)'
#if 0
    TimeEnd(B_NDIAG_END1);
    double t = TimeCal(B_NDIAG_START1,B_NDIAG_END1);
    switch (formula) {
    case F1: com.B_F1 += t; break;
    case F2: com.B_F2 += t; break;
    case F3: com.B_F3 += t; break;
    }
#endif
  } // end of 'for (int l)'
}
void MPointCreator::ProcessCurve(const SimpleLine& rCurve,
                                 const Interval<Instant> TimeInterval,
                                 double dCurveLength)
{
    double dLength = dCurveLength < 0.0 ?
                           MMUtil::CalcLengthCurve(&rCurve, m_dNetworkScale) :
                           dCurveLength;
    if (AlmostEqual(dLength, 0.0))
    {
        AttributePtr<UPoint> pUPoint(new UPoint(TimeInterval,
                                                rCurve.StartPoint(),
                                                rCurve.EndPoint()));
        m_pResMPoint->Add(*pUPoint);
        return;
    }

    DateTime Duration = TimeInterval.end - TimeInterval.start;
    Duration.Abs();

    const bool bStartsSmaller = rCurve.GetStartSmaller();

    Instant TimeStart(TimeInterval.start);

    const int nHalfSegments = rCurve.Size();
    if (nHalfSegments <= 0)
        return;

    assert(nHalfSegments % 2 == 0);

    LRS lrs(bStartsSmaller ? 0.0 : rCurve.Length(), 0);
    int lrsPosAkt = 0;
    if (!const_cast<SimpleLine&>(rCurve).Get(lrs, lrsPosAkt))
    {
        assert(false);
        return;
    }

    LRS lrsAkt;
    rCurve.Get(lrsPosAkt, lrsAkt);
    HalfSegment hs;
    rCurve.Get(lrsAkt.hsPos, hs);

    double dLengthHS = MMUtil::CalcDistance(hs.GetLeftPoint(),
                                            hs.GetRightPoint(),
                                            m_dNetworkScale);
    DateTime TimeEnd = TimeStart +
                       DateTime(datetime::durationtype,
                                    (uint64_t)(((Duration.millisecondsToNull()
                                                 / dLength) * dLengthHS) + .5));

    Interval<Instant> TimeIntervalAkt(TimeStart, TimeEnd,
                                      true, TimeStart == TimeEnd);

    Point Pt1(false);
    Point Pt2(false);

    if (const_cast<SimpleLine&>(rCurve).StartsSmaller())
    {
        Pt1 = hs.GetDomPoint();
        Pt2 = hs.GetSecPoint();
    }
    else
    {
        Pt1 = hs.GetSecPoint();
        Pt2 = hs.GetDomPoint();
    }

    AttributePtr<UPoint> pUPoint(new UPoint(TimeIntervalAkt, Pt1, Pt2));
    m_pResMPoint->Add(*pUPoint);

    TimeStart = TimeEnd;

    if (bStartsSmaller)
        ++lrsPosAkt;
    else
        --lrsPosAkt;

    while (lrsPosAkt >= 0 && lrsPosAkt < nHalfSegments / 2)
    {
        rCurve.Get(lrsPosAkt, lrsAkt);
        rCurve.Get(lrsAkt.hsPos, hs);

        double dLengthHS = MMUtil::CalcDistance(hs.GetLeftPoint(),
                                                hs.GetRightPoint(),
                                                m_dNetworkScale);

        DateTime TimeEnd = TimeStart +
                           DateTime(datetime::durationtype,
                                    (uint64_t)(((Duration.millisecondsToNull()
                                                 / dLength) * dLengthHS) + .5));

        Interval<Instant> TimeIntervalAkt(TimeStart, TimeEnd,
                                          true, TimeStart == TimeEnd);

        if (AlmostEqual(Pt2, hs.GetDomPoint()))
        {
            Pt1 = hs.GetDomPoint();
            Pt2 = hs.GetSecPoint();
        }
        else
        {
            Pt1 = hs.GetSecPoint();
            Pt2 = hs.GetDomPoint();
        }

        /*if (AlmostEqual(Pt2, rCurve.EndPoint()))
            TimeStart = TimeInterval.end;*/

        AttributePtr<UPoint> pUPoint(new UPoint(TimeIntervalAkt, Pt1, Pt2));
        m_pResMPoint->Add(*pUPoint);

        TimeStart = TimeEnd;

        if (bStartsSmaller)
            ++lrsPosAkt;
        else
            --lrsPosAkt;
    }
}