Changeset 35aef3 in git


Ignore:
Timestamp:
Jun 17, 2015, 2:30:30 PM (8 years ago)
Author:
Stephan Oberfranz <oberfran@…>
Branches:
(u'spielwiese', '8e0ad00ce244dfd0756200662572aef8402f13d5')
Children:
500e4b69e2df574c6ae8023f32cbdfbdbd0d5e8e
Parents:
3e1c75620dfadd12d3798a1aee9d665e5388539d
Message:
randomization fixed
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Singular/walk.cc

    r3e1c75 r35aef3  
    43614361         target_weight != NULL && G->m[0] != NULL);
    43624362
     4363  intvec* next_weight1 = MkInterRedNextWeight(curr_weight,target_weight,G);
     4364  if(weight_rad == 0)
     4365  {
     4366    return(next_weight1);
     4367  }
     4368
    43634369  int i,weight_norm,nV = currRing->N;
    4364   intvec* next_weight2;
     4370  intvec* next_weight2 = new intvec(nV);
    43654371  intvec* next_weight22 = new intvec(nV);
    43664372  intvec* result = new intvec(nV);
    43674373
    4368   intvec* next_weight1 =MkInterRedNextWeight(curr_weight,target_weight,G);
     4374  ideal G_test, G_test2;
     4375
    43694376  //compute a random next weight vector "next_weight2"
    43704377  while(1)
     
    43764383      for(i=0; i<nV; i++)
    43774384      {
    4378         (*next_weight22)[i] = rand() % 60000 - 30000;
    4379         weight_norm = weight_norm + (*next_weight22)[i]*(*next_weight22)[i];
     4385        (*next_weight2)[i] = rand() % 60000 - 30000;
     4386        weight_norm = weight_norm + (*next_weight2)[i]*(*next_weight2)[i];
    43804387      }
    43814388      weight_norm = 1 + floor(sqrt(weight_norm));
     
    43844391    for(i=0; i<nV; i++)
    43854392    {
    4386       if((*next_weight22)[i] < 0)
    4387       {
    4388         (*next_weight22)[i] = 1 + (*curr_weight)[i] + floor(weight_rad*(*next_weight22)[i]/weight_norm);
     4393      if((*next_weight2)[i] < 0)
     4394      {
     4395        (*next_weight2)[i] = 1 + (*curr_weight)[i] + floor(weight_rad*(*next_weight2)[i]/weight_norm);
    43894396      }
    43904397      else
    43914398      {
    4392         (*next_weight22)[i] = (*curr_weight)[i] + floor(weight_rad*(*next_weight22)[i]/weight_norm);
    4393       }
    4394     }
    4395 
    4396     if(test_w_in_ConeCC(G, next_weight22) == 1)
    4397     {
    4398       next_weight2 = MkInterRedNextWeight(next_weight22,target_weight,G);
     4399        (*next_weight2)[i] = (*curr_weight)[i] + floor(weight_rad*(*next_weight2)[i]/weight_norm);
     4400      }
     4401    }
     4402   
     4403    if(test_w_in_ConeCC(G, next_weight2) == 1)
     4404    {
     4405      PrintS("\n Hier 1\n");
     4406      G_test2 = MwalkInitialForm(G, next_weight2);
     4407      PrintS("\n Hier 2\n");
     4408      if(maxlengthpoly(G_test2) <= 1)
     4409      {
     4410        next_weight2 = MkInterRedNextWeight(next_weight2,target_weight,G);
     4411      }
     4412      idDelete(&G_test2);
     4413
    43994414      if(MivAbsMax(next_weight2)>1147483647)
    44004415      {
     
    44044419        }
    44054420        i = 0;
    4406         /* reduce the size of the maximal entry of the vector*/
    4407         while(test_w_in_ConeCC(G,next_weight22))
     4421        // reduce the size of the maximal entry of the vector
     4422        while(test_w_in_ConeCC(G,next_weight22) == 1)
    44084423        {
    44094424          (*next_weight2)[i] = (*next_weight22)[i];
     
    44114426          (*next_weight22)[i] = floor(0.1*(*next_weight22)[i] + 0.5);
    44124427        }
    4413       }
    4414       delete next_weight22;
     4428        delete next_weight22;
     4429      }
    44154430      break;
    44164431    }
     4432    weight_rad++;
    44174433  }
    44184434 
    44194435  // compute "usual" next weight vector
    44204436  intvec* next_weight = MwalkNextWeightCC(curr_weight,target_weight, G);
    4421   ideal G_test = MwalkInitialForm(G, next_weight);
    4422   ideal G_test2 = MwalkInitialForm(G, next_weight2);
     4437  G_test = MwalkInitialForm(G, next_weight);
     4438  G_test2 = MwalkInitialForm(G, next_weight2);
    44234439
    44244440  // compare next weights
     
    44264442  {
    44274443    ideal G_test1 = MwalkInitialForm(G, next_weight1);
    4428     if(G_test1->m[0] != NULL && maxlengthpoly(G_test1) < maxlengthpoly(G_test))//if(IDELEMS(G_test1) < IDELEMS(G_test))
    4429     {
    4430       if(G_test2->m[0] != NULL && maxlengthpoly(G_test2) < maxlengthpoly(G_test1))//if(IDELEMS(G_test2) < IDELEMS(G_test1))
     4444    if(G_test1->m[0] != NULL && maxlengthpoly(G_test1) < maxlengthpoly(G_test))
     4445    {
     4446      if(G_test2->m[0] != NULL && maxlengthpoly(G_test2) < maxlengthpoly(G_test1))
    44314447      {
    44324448        for(i=0; i<nV; i++)
     
    44454461    else
    44464462    {
    4447       if(G_test2->m[0] != NULL && maxlengthpoly(G_test2) < maxlengthpoly(G_test))//if(IDELEMS(G_test2) < IDELEMS(G_test)) // |G_test2| < |G_test| <= |G_test1|
     4463      if(G_test2->m[0] != NULL && maxlengthpoly(G_test2) < maxlengthpoly(G_test))
    44484464      {
    44494465        for(i=0; i<nV; i++)
     
    44654481  {
    44664482    Overflow_Error = FALSE;
    4467     if(G_test2->m[0] != NULL && maxlengthpoly(G_test2) < maxlengthpoly(G_test))//if(IDELEMS(G_test2) < IDELEMS(G_test))
     4483    if(G_test2->m[0] != NULL && maxlengthpoly(G_test2) < maxlengthpoly(G_test))
    44684484    {
    44694485      for(i=1; i<nV; i++)
     
    44804496    }
    44814497  }
    4482   //PrintS("\n MWalkRandomNextWeight: Ende ok!\n");
     4498
    44834499  idDelete(&G_test);
    44844500  idDelete(&G_test2);
     
    54035419  Set_Error(FALSE);
    54045420  Overflow_Error = FALSE;
    5405   //BOOLEAN endwalks = FALSE;
     5421  BOOLEAN endwalks = FALSE;
    54065422#ifdef TIME_TEST
    54075423  clock_t tinput, tostd, tif=0, tstd=0, tlift=0, tred=0, tnw=0;
     
    54225438  intvec* curr_weight = new intvec(nV);
    54235439  intvec* target_weight = new intvec(nV);
    5424   intvec* exivlp = Mivlp(nV);
    54255440  intvec* next_weight= new intvec(nV);
    5426 /*
    5427   intvec* tmp_weight = new intvec(nV);
    5428   for(i=0; i<nV; i++)
    5429   {
    5430     (*tmp_weight)[i] = (*target_M)[i];
    5431   }
    5432 */
     5441
    54335442  for(i=0; i<nV; i++)
    54345443  {
     
    54765485
    54775486  nwalk = 0;
     5487
     5488#ifdef TIME_TEST
     5489  to = clock();
     5490#endif
     5491  Gomega = MwalkInitialForm(G, curr_weight); // compute an initial form ideal of <G> w.r.t. "curr_vector"
     5492#ifdef TIME_TEST
     5493  tif = tif + clock()-to; //time for computing initial form ideal
     5494#endif
     5495
    54785496  while(1)
    54795497  {
    54805498    nwalk ++;
    54815499    nstep ++;
    5482 #ifdef TIME_TEST
    5483     to = clock();
    5484 #endif
    5485 
    5486     Gomega = MwalkInitialForm(G, curr_weight); // compute an initial form ideal of <G> w.r.t. "curr_vector"
    5487     //polylength = 1 if there is a polynomial in Gomega with at least 3 monomials and 0 otherwise
    5488     polylength = lengthpoly(Gomega);
    5489 #ifdef TIME_TEST
    5490     tif = tif + clock()-to; //time for computing initial form ideal
    5491 #endif
    5492 //#ifdef CHECK_IDEAL_MWALK
    54935500    if(printout > 1)
    54945501    {
    54955502      idString(Gomega,"//** Mrwalk: Gomega");
    54965503    }
    5497 //#endif
    5498     // test whether target cone is reached
    5499 /*    if(test_w_in_ConeCC(G,target_weight) == 1)
    5500     {
    5501       endwalks = TRUE;
    5502     }*/
    55035504    if(reduction == 0)
    55045505    {
    5505      
    55065506      FF = middleOfCone(G,Gomega);
    5507      
    55085507      if(FF != NULL)
    55095508      {
     
    55415540     {
    55425541       newRing = VMrDefault(curr_weight); // define a new ring with ordering "(a(curr_weight),lp)
    5543        //newRing = VMrRefine(curr_weight,target_weight); //define a new ring with ordering "(a(curr_weight),Wp(target_weight))"
    55445542     }
    55455543     else
     
    56125610    rChangeCurrRing(targetRing);
    56135611    G = idrMoveR(G,newRing,currRing);
     5612
    56145613    // test whether target cone is reached
    56155614    if(reduction !=0 && test_w_in_ConeCC(G,curr_weight) == 1)
     
    56235622    baseRing = currRing;
    56245623
    5625 
    56265624    NEXT_VECTOR:
    56275625#ifdef TIME_TEST
     
    56295627#endif
    56305628    next_weight = MwalkNextWeightCC(curr_weight,target_weight,G);
     5629#ifdef TIME_TEST
     5630    tnw = tnw + clock() - to;
     5631#endif
     5632
     5633#ifdef TIME_TEST
     5634    to = clock();
     5635#endif
     5636    Gomega = MwalkInitialForm(G, next_weight); // compute an initial form ideal of <G> w.r.t. "curr_vector"
     5637#ifdef TIME_TEST
     5638    tif = tif + clock()-to; //time for computing initial form ideal
     5639#endif
     5640
     5641    //polylength = 1 if there is a polynomial in Gomega with at least 3 monomials and 0 otherwise
     5642    polylength = lengthpoly(Gomega);
    56315643    if(polylength > 0)
    56325644    {
     
    56345646      //low-dimensional facet of the cone
    56355647      delete next_weight;
     5648#ifdef TIME_TEST
     5649    to = clock();
     5650#endif
    56365651      next_weight = MWalkRandomNextWeight(G, curr_weight, target_weight, weight_rad, pert_deg);
    5637     }
    56385652#ifdef TIME_TEST
    56395653    tnw = tnw + clock() - to;
    56405654#endif
     5655      idDelete(&Gomega);
     5656#ifdef TIME_TEST
     5657    to = clock();
     5658#endif
     5659      Gomega = MwalkInitialForm(G, next_weight);
     5660#ifdef TIME_TEST
     5661    tif = tif + clock()-to; //time for computing initial form ideal
     5662#endif
     5663    }
     5664
     5665    // test whether target weight vector is reached
     5666    if(MivComp(next_weight, ivNull) == 1 || MivComp(target_weight,curr_weight) == 1)
     5667    {
     5668      baseRing = currRing;
     5669      delete next_weight;
     5670      break;
     5671    }
     5672
    56415673//#ifdef PRINT_VECTORS
    56425674    if(printout > 0)
     
    56455677    }
    56465678//#endif
    5647     if(MivComp(next_weight, ivNull) == 1 || MivComp(target_weight,curr_weight) == 1)// || endwalks == TRUE)
    5648     {/*
    5649 //#ifdef CHECK_IDEAL_MWALK
    5650       if(printout > 0)
    5651       {
    5652         PrintS("\n//** Mrwalk: entering last cone.\n");
    5653       }
    5654 //#endif
    5655 
    5656       Gomega = MwalkInitialForm(G, curr_weight); // compute an initial form ideal of <G> w.r.t. "curr_vector"
    5657       if(target_M->length() == nV)
    5658       {
    5659         newRing = VMrDefault(target_weight); // define a new ring with ordering "(a(curr_weight),lp)
    5660       }
    5661       else
    5662       {
    5663         newRing = VMatrDefault(target_M);
    5664       }
    5665       rChangeCurrRing(newRing);
    5666       Gomega1 = idrMoveR(Gomega, baseRing,currRing);
    5667       idDelete(&Gomega);
    5668 //#ifdef CHECK_IDEAL_MWALK
    5669       if(printout > 1)
    5670       {
    5671         idString(Gomega1, "//** Mrwalk: Gomega");
    5672       }
    5673       PrintS("\n //** Mrwalk: kStd(Gomega)");
    5674 //#endif
    5675       M = kStd(Gomega1,NULL,testHomog,NULL,NULL,0,0,NULL);
    5676 //#ifdef CHECK_IDEAL_MWALK
    5677       if(printout > 1)
    5678       {
    5679         idString(M,"//** Mrwalk: M");
    5680       }
    5681 //#endif
    5682       rChangeCurrRing(baseRing);
    5683       M1 =  idrMoveR(M, newRing,currRing);
    5684       idDelete(&M);
    5685       Gomega2 = idrMoveR(Gomega1, newRing,currRing);
    5686       idDelete(&Gomega1);
    5687       //PrintS("\n //** Mrwalk: MLifttwoIdeal");
    5688       F = MLifttwoIdeal(Gomega2, M1, G);
    5689 //#ifdef CHECK_IDEAL_MWALK
    5690       if(printout > 2)
    5691       {
    5692         idString(F,"//** Mrwalk: F");
    5693       }
    5694 //#endif
    5695       idDelete(&Gomega2);
    5696       idDelete(&M1);
    5697       rChangeCurrRing(newRing); // change the ring to newRing
    5698       G = idrMoveR(F,baseRing,currRing);
    5699       idDelete(&F);
    5700       baseRing = currRing;
    5701       si_opt_1 = save1; //set original options, e. g. option(RedSB)
    5702       idSkipZeroes(G);
    5703 #ifdef TIME_TEST
    5704       to = clock();
    5705 #endif
    5706       //PrintS("\n //**Mrwalk: Interreduce");
    5707       //interreduce the Groebner basis <G> w.r.t. currRing
    5708       //G = kInterRedCC(G,NULL);
    5709 #ifdef TIME_TEST
    5710       tred = tred + clock() - to;
    5711 #endif
    5712       idSkipZeroes(G);
    5713       delete next_weight;*/
    5714       break;
    5715     }
    57165679
    57175680    for(i=nV-1; i>=0; i--)
    57185681    {
    5719       //(*tmp_weight)[i] = (*curr_weight)[i];
    57205682      (*curr_weight)[i] = (*next_weight)[i];
    57215683    }
     
    57275689  idDelete(&G);
    57285690  si_opt_1 = save1; //set original options, e. g. option(RedSB)
    5729   //delete tmp_weight;
    57305691  delete ivNull;
    5731   delete exivlp;
    57325692#ifndef BUCHBERGER_ALG
    57335693  delete last_omega;
     
    60075967    if(reduction == 0 && nstep > 1)
    60085968    {
     5969/*
    60095970      // check whether weight vector is in the interior of the cone
    60105971      while(1)
     
    60365997        }
    60375998      }
     5999*/
     6000      FF = middleOfCone(G,Gomega);
     6001      if(FF != NULL)
     6002      {
     6003        idDelete(&G);
     6004        G = idCopy(FF);
     6005        idDelete(&FF);
     6006        goto NEXT_VECTOR;
     6007      }
    60386008    }
    60396009
     
    61576127      break;
    61586128
     6129    NEXT_VECTOR:
    61596130    to=clock();
    61606131    // compute a next weight vector
     
    62896260  {
    62906261    si_opt_1 &= (~Sy_bit(OPT_REDSB)); // no reduced Groebner basis
    6291     //si_opt_1 &= (~Sy_bit(OPT_REDTAIL)); // not tail reductions
    6292     //si_opt_1|=(Sy_bit(OPT_REDTAIL)|Sy_bit(OPT_REDSB));
     6262    si_opt_1 &= (~Sy_bit(OPT_REDTAIL)); // not tail reductions
    62936263  }
    62946264  Set_Error(FALSE);
     
    64296399    ivString(target_weight, "//** Mprwalk: new target weight");
    64306400  }
     6401
     6402#ifdef TIME_TEST
     6403  to = clock();
     6404#endif
     6405  Gomega = MwalkInitialForm(G, curr_weight); // compute an initial form ideal of <G> w.r.t. "curr_vector"
     6406#ifdef TIME_TEST
     6407  tif = tif + clock()-to; //time for computing initial form ideal
     6408#endif
     6409
    64316410  while(1)
    64326411  {
    64336412    nstep ++;
    64346413    to = clock();
    6435     // compute an initial form ideal of <G> w.r.t. the weight vector
    6436     // "curr_weight"
    6437     Gomega = MwalkInitialForm(G, curr_weight);
     6414    // compute an initial form ideal of G w.r.t. the weight vector "curr_weight"
     6415/*    Gomega = MwalkInitialForm(G, curr_weight);
    64386416    polylength = lengthpoly(Gomega);
     6417*/
    64396418//#ifdef CHECK_IDEAL_MWALK
    64406419    if(printout > 1)
     
    64466425    if(reduction == 0 && nstep > 1)
    64476426    {
     6427/*
    64486428      // check whether weight vector is in the interior of the cone
    64496429      while(1)
     
    64756455        }
    64766456      }
     6457*/
     6458      FF = middleOfCone(G,Gomega);
     6459      if(FF != NULL)
     6460      {
     6461        idDelete(&G);
     6462        G = idCopy(FF);
     6463        idDelete(&FF);
     6464        goto NEXT_VECTOR;
     6465      }
    64776466    }
    64786467
     
    64856474    }
    64866475#endif
    6487 
    6488     tif = tif + clock()-to;
    64896476
    64906477#ifndef  BUCHBERGER_ALG
     
    66036590      break;
    66046591
     6592Print("\n Next weight");
     6593    NEXT_VECTOR:
     6594#ifdef TIME_TEST
     6595    to = clock();
     6596#endif
     6597    next_weight = next_weight = MkInterRedNextWeight(curr_weight,target_weight, G);
     6598#ifdef TIME_TEST
     6599    tnw = tnw + clock() - to;
     6600#endif
     6601
     6602#ifdef TIME_TEST
     6603    to = clock();
     6604#endif
     6605    Gomega = MwalkInitialForm(G, next_weight); // compute an initial form ideal of <G> w.r.t. "curr_vector"
     6606#ifdef TIME_TEST
     6607    tif = tif + clock()-to; //time for computing initial form ideal
     6608#endif
     6609
     6610    //polylength = 1 if there is a polynomial in Gomega with at least 3 monomials and 0 otherwise
     6611    polylength = lengthpoly(Gomega);
     6612    if(polylength > 0)
     6613    {
     6614      Print("\n there is a polynomial in Gomega with at least 3 monomials");
     6615      //low-dimensional facet of the cone
     6616      delete next_weight;
     6617#ifdef TIME_TEST
     6618      to = clock();
     6619#endif
     6620      next_weight = MWalkRandomNextWeight(G, curr_weight, target_weight, weight_rad, op_deg);
     6621#ifdef TIME_TEST
     6622      tnw = tnw + clock() - to;
     6623#endif
     6624      idDelete(&Gomega);
     6625#ifdef TIME_TEST
     6626      to = clock();
     6627#endif
     6628      Gomega = MwalkInitialForm(G, next_weight);
     6629#ifdef TIME_TEST
     6630      tif = tif + clock()-to; //time for computing initial form ideal
     6631#endif
     6632    }
     6633
     6634/*
    66056635    to=clock();
    6606 
    66076636    next_weight = MkInterRedNextWeight(curr_weight,target_weight, G);
    66086637    if(polylength > 0)
     
    66166645    }
    66176646    tnw=tnw+clock()-to;
     6647*/
    66186648//#ifdef PRINT_VECTORS
    66196649    if(printout > 0)
     
    66266656    {
    66276657      ntwC = 0;
    6628       //ntestomega = 1;
    66296658      //Print("\n// ring r%d = %s;\n", nstep, rString(currRing));
    66306659      //idElements(G, "G");
     
    67166745      Eresult = idrMoveR(eF1, exTargetRing,currRing);
    67176746    }
    6718     else{
     6747    else
     6748    {
    67196749      rChangeCurrRing(XXRing);
    67206750      Eresult = idrMoveR(F1, TargetRing,currRing);
    67216751    }
    67226752  }
    6723   else {
     6753  else
     6754  {
    67246755    rChangeCurrRing(XXRing);
    67256756    Eresult = idrMoveR(G, newRing,currRing);
     
    72877318    if(polylength > 0 && G->m[0] != NULL)
    72887319    {
    7289      
    7290       PrintS("\n**// rec_r_fractal_call: there is a polynomial in Gomega with at least 3 monomials, low-dimensional facet of the cone.\n");
    7291      
     7320      if(printout > 0)
     7321      {
     7322        PrintS("\n**// rec_r_fractal_call: there is a polynomial in Gomega with at least 3 monomials, low-dimensional facet of the cone.\n");
     7323      }
    72927324      delete next_vect;
    72937325      next_vect = MWalkRandomNextWeight(G,omega,omega2,weight_rad,nlev);
    7294       if(isNegNolVector(next_vect)==1)
     7326      if(isNegNolVector(next_vect) == 1)
    72957327      {
    72967328        delete next_vect;
     
    73767408          delete next_vect;
    73777409          next_vect = MWalkRandomNextWeight(G,omega,omega2,weight_rad,nlev);
    7378           if(isNegNolVector(next_vect)==1)
     7410          if(isNegNolVector(next_vect) == 1)
    73797411          {
    73807412            delete next_vect;
Note: See TracChangeset for help on using the changeset viewer.