//insert & rotation functions: void leftRotation(NodeT** root) { NodeT* aux=(*root)->right; (*root)->right=aux->left; aux->left=(*root); (*root)->height=maxx(height((*root)->left), height((*root)->right))+1; aux->height=maxx(height(aux->right), (*root)->height)+1; (*root)=aux; }
bool intersects(PRECISION x, PRECISION y) const { if (x < minx() || maxx() < x || y < miny() || maxy() < y) { return false; } else { return true; } }
//--------------------------------------------------------------- // get cut-points void getcutpoints(int nc, int n_cov, int n_samp, std::vector<std::vector<double> >& X, xinfo& xi){ double xinc; //increments double xx; std::vector<double> minx(n_cov,R_PosInf); // to store the minimum of each of the individual specific pred std::vector<double> maxx(n_cov,R_NegInf);// to store the max of each of the individual specific pred for(int j=0;j<n_cov;j++) { for(int i=0;i<n_samp;i++) { xx = X[i][j]; if(xx < minx[j]) minx[j]=xx; if(xx > maxx[j]) maxx[j]=xx; } } //make grid of nc cutpoints between min and max for each x. xi.resize(n_cov); for(int i=0;i<n_cov;i++) { xinc = (maxx[i]-minx[i])/(nc+1.0); xi[i].resize(nc); for(int j=0;j<nc;j++) xi[i][j] = minx[i] + (j+1)*xinc; } }
NodeT* insertNodeAVLtree(NodeT* root, int data) { if(root==NULL) return createNodeT(data); else { if(root->data < data) root->right=insertNodeAVLtree(root->right, data); else root->left=insertNodeAVLtree(root->left, data); } root->height=maxx(height(root->left), height(root->right))+1; int aux=balanceFactor(root); if(aux>1) { if(root->left->data > data)//RR rightRotation(&root); else//LR LeftRight(&root); } else if(aux<-1) { if(root->right->data < data)//LL leftRotation(&root); else//RL RightLeft(&root); } //else return root; }
int main() { double x; int ji,i,f,k,m,xe,xs,flag; ji=0; while(scanf("%d",&n),n) { ji++; getchar(); chu(); for(i=0;i<n;i++) { gets(ch[i]); } scanf("%d",&m); getchar(); for(i=0;i<m;i++) { scanf("%s%lf%s",s,&x,e); xs=finds(); xe=finde(); if(-1==map[xs][xe]||x>map[xs][xe]) { map[xs][xe]=x; } } for(k=0;k<n;k++) { for(i=0;i<n;i++) { for(f=0;f<n;f++) { if(-1!=map[i][k]&&-1!=map[k][f]) { map[i][f]=maxx(map[i][f],map[i][k]*map[k][f]); } } } } flag=0; for(i=0;i<n;i++) { if(1<map[i][i]) { flag=1; break; } } if(1==flag) { printf("Case %d: Yes\n",ji); } else { printf("Case %d: No\n",ji); } } return 0; }
int MaxFail(void) { int i = 0, t = 0, bra = 0, count = 0; while (i != 0x7f && count < 54) { if (Mev[i].StepInfo == 0) { Mev[i].StepInfo = 1003; } t = maxx(Mev[i].StepInfo, t); if (Mev[i].trace != (i + 1)) { bra++; } i = Mev[i].trace; ++count; } if (count >= 54) { return 1; } else { return t; } }
bool Rect::intersects(const Rect& other) const { if (other.maxx() < minx() || other.minx() > maxx() || other.maxy() < miny() || other.miny() > maxy()) { return false; } else { return true; } }
int check(int p,int q,int pp,int qq,int step) { int i,l,r,x; int direc=pp>p?1:-1; //printf("%d %d %d\n",l,r,x); for(i=1;i<=step;i++) { l=maxx(1,maxx(q-i,qq-(dist-i))); //printf("%d %d %d %d\n",i,l,r,x); r=minn(n,minn(q+i,qq+(dist-i))); x=p+direc*i; //printf("%d %d %d %d\n",i,l,r,x); if(((x==p3-i||x==p3+i)&&havecross(l,r,q3-i,q3+i)) ||(aabs(p3,x)<i&&(inbox(q3-i,l,r)||inbox(q3+i,l,r)))) return i; } return INF; }
// Offsets member bound box at [i] and align with (x, y), in direction <x_dir, y_dir> // stores corresponding offset, and returns modified bounding box bound_box box_offset_align(size_t i, double x, double y, int x_dir, int y_dir) const { auto box = member_boxes_[i]; auto & offset = member_offsets_[i]; offset.x = x - (x_dir == 0 ? input_origin_.x : (x_dir < 0 ? box.maxx() : box.minx())); offset.y = y - (y_dir == 0 ? input_origin_.y : (y_dir < 0 ? box.maxy() : box.miny())); box.move(offset.x, offset.y); return box; }
/** * Calculate mission penalty due to missed milestones and duration. * * \param plr current player * \return penalty * * \note Call only when Mis is valid */ char PrestMin(char plr) { int i, j, Neg = 0; Neg = 0; j = 0; if (Mis.Index == 0) { return 0; } for (i = 0; i < 5; i++) { j = maxx(j, PrestMap(Mis.PCat[i])); } /* walk all milestones lower than maximum required for mission */ for (i = 0; i <= j; ++i) { /* if milestone not met, then add penalty */ if (Data->Mile[plr][i] == 0) { Neg += 3; } } Neg = Neg + (plr ? Data->Def.Lev2 : Data->Def.Lev1) - 2; // Neg -= (2 - ((plr == 0) ? Data->Def.Lev1 : Data->Def.Lev2)); Neg = maxx(Neg, 0); /* Index 2 = Manned suborbital * Index 4 = Manned orbital * Index 6 = Manned orbital EVA */ if (Mis.Index != 2 && Mis.Index != 4 && Mis.Index != 6 && (Mis.Days - Data->P[plr].DurLevel) > 1) { // Raised this from "> 0" to disable broken Duration penalty system -Leon Neg += 5 * (Mis.Days - Data->P[plr].DurLevel); } return Neg; }
void st() { int k,m,i,f; k=(int)(log((double)n)/log(2.0)); for(f=1;f<=k;f++) { for(i=1;i+(1<<j)-1 <= n;i++) { m=i+(1<<(j-1)); dp[i][f]=maxx(dp[i][f-1],dp[m][f-1]); } } }
NodeT* createBinaryTree(FILE* f) { NodeT* p; char* data=(char*)malloc(sizeof(char)*100); fscanf(f, "%s", data); if(strcmp(data, "*")==0) return NULL; else { p=createNodeT(atoi(data)); p->left=createBinaryTree(f); p->right=createBinaryTree(f); p->height=maxx(height(p->left), height(p->right))+1; } return p; }
int main() { int n,len,sum,extra,l; char a[300],b[300],c[300]; scanf("%d",&n); getchar(); while(n--) { scanf("%s %s",a,b); len1 = strlen(a); len2 = strlen(b); len = maxx()-1; i = 0; j = 0; l = 0; sum = 0; extra = 0; while(1) { if(i>len1-1) a[i] = '0'; if(j>len2-1) b[j] = '0'; sum = (a[i++]-'0')+(b[j++]-'0')+extra; if(sum>=10) { sum = sum - 10; extra = 1; } else extra = 0; c[l++] = sum + '0'; if(l>len && extra == 0) break; } c[l] = '\0'; perfect(c); memset(c,'\0',sizeof(c)); printf("\n"); } return 0; }
void CalcPresRev(void) { int16_t *ip; int val, max, min, i, j; char plr; if (Data->Year == 57 && Data->Season == 0) { return; } // Move PresRev down One for (j = 0; j < NUM_PLAYERS; j++) for (i = 4; i > 0; i--) { Data->P[j].PresRev[i] = Data->P[j].PresRev[i - 1]; } Data->P[0].Prestige = Data->P[1].Prestige = 0; // Clear Prest when finished for (plr = 0; plr < NUM_PLAYERS; plr++) { ip = &Data->P[plr].PresRev[0]; max = maxx(Data->P[plr].tempPrestige[0], Data->P[plr].tempPrestige[1]); min = minn(Data->P[plr].tempPrestige[0], Data->P[plr].tempPrestige[1]); val = ((max >= 0 && min >= 0) || (max <= 0 && min <= 0)) ? max + min : max / 2 + min; *ip = (val < 0 && (*ip < 4)) ? *ip + 1 : ((val > 1 && val <= 10) ? *ip - 1 : ((val >= 11 && val <= 20) ? ((*ip < 4) ? *ip - 1 : *ip - 2) : ((val >= 21) ? ((*ip < 4) ? *ip - 1 : *ip - 3) : ((val >= -9 && val <= 0) ? *ip + 1 : ((val <= -10) ? ((plr == 0) ? *ip + Data->Def.Lev1 + 1 : *ip + Data->Def.Lev2 + 1) : *ip))))); *ip = (*ip > 16) ? 16 : ((*ip < 1) ? 1 : *ip); Data->P[plr].tempPrestige[0] = 0; Data->P[plr].tempPrestige[1] = 0; Data->P[plr].PresRev[0] += (Data->P[plr].PresRev[0] > Data->P[abs(plr - 1)].PresRev[0]) ? 1 : 0; } }
void dy_initpivrej (int sze) /* Allocate the pivrej control structure and an initial pivrejlst array. Parameter: sze: allocated capacity of the pivot rejection list */ { pivrej_ctl.sze = maxx(sze,5) ; pivrejlst = (pivrej_struct *) MALLOC(pivrej_ctl.sze*sizeof(pivrej_struct)) ; pivrej_ctl.cnt = 0 ; pivrej_ctl.mad = 0 ; pivrej_ctl.sing = 0 ; pivrej_ctl.iter_reduced = -1 ; pivrej_ctl.savedtol = dy_tols->pivot ; pivrej_ctl.pivmul = 1000.0 ; # ifdef DYLP_STATISTICS if (dy_stats != NULL) dy_stats->pivrej.min_pivtol = dy_tols->pivot ; # endif return ; }
/* lis() returns the length of the longest increasing subsequence in arr[] of size n */ int lis( int arr[], int n ) { int *lis, i, j, max = 0; lis = (int*) malloc ( sizeof( int ) * n ); /* Initialize LIS values for all indexes */ for (i = 0; i < n; i++ ) lis[i] = 1; /* Compute optimized LIS values in bottom up manner */ for (i = 1; i < n; i++ ) for (j = 0; j < i; j++ ) if ( arr[i] > arr[j] && lis[i] < lis[j] + 1) lis[i] = lis[j] + 1; /* Pick maximum of all LIS values */ for (i = 0; i < n; i++ ) max = maxx(lis[i], max); /* Free memory to avoid memory leak */ free(lis); return max; }
/** * Calculate and return the width/height * ie. maxx/maxy - minx/miny respectively. */ PRECISION get_width() const { return maxx() - minx(); }
/* * Intoarce coordonata x a centrului figurii. */ double get_centerx() { return minx()+(maxx()-minx())/2; }
double clc(double a,double b,double c) { double top=-0.5*b/a; if(top>=t&&top<=1)return c-0.25*b*b/a; else return maxx(a*t*t+b*t+c,a+b+c); }
double consys_infnormcol (consys_struct *consys, int colndx) /* This routine computes the infinity-norm of a column: MAX{i} |a<i,j>|. Parameters: consys: constraint system colndx: column Returns: value of the norm, or NaN if the calculation goes awry */ { double norm ; colhdr_struct *colhdr ; coeff_struct *coeff ; # if defined(DYLP_PARANOIA) || !defined(DYLP_NDEBUG) const char *rtnnme = "consys_infnormcol" ; # endif # ifdef DYLP_PARANOIA if (consys == NULL) { errmsg(2,rtnnme,"consys") ; return (quiet_nan(0)) ; } if (consys->mtx.cols == NULL) { errmsg(101,rtnnme,consys->nme,"column header") ; return (quiet_nan(0)) ; } # endif # ifndef DYLP_NDEBUG if (colndx <= 0 || colndx > consys->varcnt) { errmsg(102,rtnnme,consys->nme,"column",colndx,1,consys->varcnt) ; return (quiet_nan(0)) ; } # endif colhdr = consys->mtx.cols[colndx] ; # ifdef DYLP_PARANOIA if (colhdr == NULL) { errmsg(103,rtnnme,consys->nme,"column",colndx) ; return (quiet_nan(0)) ; } if (colndx != colhdr->ndx) { errmsg(126,rtnnme,consys->nme,"column",colhdr,colhdr->ndx,colndx,colhdr) ; return (quiet_nan(0)) ; } # endif norm = 0 ; for (coeff = colhdr->coeffs ; coeff != NULL ; coeff = coeff->colnxt) { # ifdef DYLP_PARANOIA if (coeff->rowhdr == NULL) { errmsg(125,rtnnme,consys->nme,"rowhdr",coeff,"column", consys_nme(consys,'v',colndx,FALSE,NULL),colndx) ; return (quiet_nan(0)) ; } if (coeff->rowhdr->ndx <= 0 || coeff->rowhdr->ndx > consys->varcnt) { errmsg(102,rtnnme,consys->nme,"row",coeff->rowhdr->ndx, 1,consys->varcnt) ; return (quiet_nan(0)) ; } if (coeff->rowhdr != consys->mtx.rows[coeff->rowhdr->ndx]) { errmsg(126,rtnnme,consys->nme,"row",coeff->rowhdr,coeff->rowhdr->ndx, coeff->rowhdr->ndx,consys->mtx.rows[coeff->rowhdr->ndx]) ; return (quiet_nan(0)) ; } # endif norm = maxx(fabs(coeff->val),norm) ; } return (norm) ; }
bool Rect::containsPoint(Point point) const { return point.x >= minx() && point.x <= maxx() && point.y >= miny() && point.y <= maxy(); }
bool dy_setpivparms (int curdelta, int mindelta) /* This routine exists to allow other parts of the lp code to adjust the pivot regimen used when the basis is factored. curdelta is the change in the current pivot level, mindelta the change in the minimum pivot level. A positive delta increases (tightens) the tolerances by delta steps, and a negative delta lowers (loosens) them. If either delta is 0, there's no change. A large positive or negative value slams the tolerance to the appropriate extreme. Parameters: curdelta: change to the current pivot level mindelta: change to the minimum pivot level Returns: TRUE if any change actually occurred, FALSE if we were already at the relevant limit(s) (BE CAREFUL interpreting the return value if you're changing both at once) */ { bool minretval,curretval ; # ifdef DYLP_PARANOIA const char *rtnnme = "dy_setpivparms" ; if (luf_basis == NULL) { errmsg(2,rtnnme,"luf_basis") ; return (FALSE) ; } # endif minretval = FALSE ; curretval = FALSE ; /* Adjust the minimum pivot level first. This may imply an adjustment in the current pivot level. */ if (mindelta != 0) { if ((minpivlevel <= 0 && mindelta < 0) || (minpivlevel >= MAX_PIVLEVEL && mindelta > 0)) { # ifndef DYLP_NDEBUG if ((dy_opts->print.basis >= 3) || (dy_opts->print.basis >= 2 && mindelta > 0)) { dyio_outfmt(dy_logchn,dy_gtxecho, "\n\t min. pivot ratio unchanged at %s (%d)", dy_prtpivparms(minpivlevel),minpivlevel) ; } # endif } else { minretval = TRUE ; minpivlevel += mindelta ; if (minpivlevel < 0) minpivlevel = 0 ; else if (minpivlevel > MAX_PIVLEVEL) minpivlevel = MAX_PIVLEVEL ; if (pivlevel < minpivlevel) curdelta = maxx(curdelta,(minpivlevel-pivlevel)) ; # ifndef DYLP_NDEBUG if (dy_opts->print.basis >= 2) { dyio_outfmt(dy_logchn,dy_gtxecho, "\n\t setting min. pivot ratio to %s (%d)", dy_prtpivparms(minpivlevel),minpivlevel) ; } # endif } } /* Adjust the current pivot level. */ if (curdelta != 0) { if ((pivlevel <= minpivlevel && curdelta < 0) || (pivlevel >= MAX_PIVLEVEL && curdelta > 0)) { # ifndef DYLP_NDEBUG if ((dy_opts->print.basis >= 3) || (dy_opts->print.basis >= 2 && mindelta > 0)) { dyio_outfmt(dy_logchn,dy_gtxecho, "\n\t cur. pivot ratio unchanged at %s (%d)", dy_prtpivparms(-1),pivlevel) ; } # endif } else { curretval = TRUE ; pivlevel += curdelta ; if (pivlevel < minpivlevel) pivlevel = minpivlevel ; else if (pivlevel > MAX_PIVLEVEL) pivlevel = MAX_PIVLEVEL ; luf_basis->luf->piv_tol = pivtols[pivlevel].stable ; luf_basis->luf->piv_lim = pivtols[pivlevel].look ; # ifndef DYLP_NDEBUG if (dy_opts->print.basis >= 2) { dyio_outfmt(dy_logchn,dy_gtxecho, "\n\t setting cur. pivot ratio to %s (%d)", dy_prtpivparms(-1),pivlevel) ; } # endif } } if (curretval == FALSE && minretval == FALSE) return (FALSE) ; else return (TRUE) ; }
void AILaunch(char plr) { int i, j, k = 0, l = 0, JR = 0, wgt, bwgt[7]; char boos[7], bdex[7]; for (i = 0; i < 7; i++) { bdex[i] = i; boos[i] = (i > 3) ? RocketBoosterSafety(Data->P[plr].Rocket[i - 4].Safety, Data->P[plr].Rocket[4].Safety) : Data->P[plr].Rocket[i].Safety; bwgt[i] = (i > 3) ? (Data->P[plr].Rocket[i - 4].MaxPay + Data->P[plr].Rocket[4].MaxPay) : Data->P[plr].Rocket[i].MaxPay; if (boos[i] < 60) { boos[i] = -1; // Get Rid of any Unsafe rkt systems } if (Data->P[plr].Rocket[4].Num < 1) for (j = 4; j < 7; j++) { boos[j] = -1; } for (j = 0; j < 4; j++) if (Data->P[plr].Rocket[j].Num < 1) { boos[j] = -1; } } for (i = 0; i < 3; i++) { if (Data->P[plr].Mission[i].MissionCode == 28 && Data->P[plr].DMod == 0) { Data->P[plr].Mission[i].MissionCode = 0; return; } if (Data->P[plr].Mission[i].MissionCode > 0 && Data->P[plr].Mission[i].part == 0) { whe[0] = whe[1] = -1; if (Data->P[plr].Mission[i].Joint == 1) { AIVabCheck(plr, Data->P[plr].Mission[i].MissionCode, Data->P[plr].Mission[i + 1].Prog); } else { AIVabCheck(plr, Data->P[plr].Mission[i].MissionCode, Data->P[plr].Mission[i].Prog); } if (whe[0] > 0) { if (Data->P[plr].Mission[i].Prog == 0) { BuildVAB(plr, Data->P[plr].Mission[i].MissionCode, 1, 0, Data->P[plr].Mission[i].Prog); } else { BuildVAB(plr, Data->P[plr].Mission[i].MissionCode, 1, 0, Data->P[plr].Mission[i].Prog - 1); } for (j = Mission_Capsule; j <= Mission_Probe_DM; j++) { Data->P[plr].Mission[i].Hard[j] = VAS[whe[0]][j].dex; } wgt = 0; for (j = 0; j < 4; j++) { wgt += VAS[whe[0]][j].wt; } rck[0] = -1; for (k = 0; k < 7; k++) if (boos[k] != -1 && bwgt[k] >= wgt) { if (rck[0] == -1) { rck[0] = bdex[k]; } else if (boos[k] >= boos[rck[0]]) { rck[0] = bdex[k]; } } if (rck[0] == -1) { ClrMiss(plr, i - Data->P[plr].Mission[i].part); } else { if (Data->P[plr].Mission[i].MissionCode == 1) { rck[0] = 0; } if (Data->P[plr].Mission[i].MissionCode >= 7 && Data->P[plr].Mission[i].MissionCode <= 13) { rck[0] = 1; } if (Data->P[plr].Mission[i].MissionCode == 3) { rck[0] = 1; } if (Data->P[plr].Mission[i].MissionCode == 15) { rck[0] = 1; } Data->P[plr].Mission[i].Hard[Mission_PrimaryBooster] = rck[0] + 1; } } else { // Clear Mission Data->P[plr].Mission[i].MissionCode = 0; } // joint mission part if (whe[1] > 0 && Data->P[plr].Mission[i + 1].part == 1) { if (Data->P[plr].Mission[i].Prog == 0) { BuildVAB(plr, Data->P[plr].Mission[i].MissionCode, 1, 1, Data->P[plr].Mission[i].Prog); } else { BuildVAB(plr, Data->P[plr].Mission[i].MissionCode, 1, 1, Data->P[plr].Mission[i].Prog - 1); } for (j = Mission_Capsule ; j <= Mission_Probe_DM; j++) { Data->P[plr].Mission[i + 1].Hard[j] = VAS[whe[1]][j].dex; } wgt = 0; for (j = 0; j < 4; j++) { wgt += VAS[whe[1]][j].wt; } rck[1] = -1; for (k = 0; k < 7; k++) if (boos[k] != -1 && bwgt[k] >= wgt) { if (rck[1] == -1) { rck[1] = bdex[k]; } else if (boos[k] >= boos[rck[1]]) { rck[1] = bdex[k]; } } if (rck[1] == -1) { rck[1] = Data->P[plr].Mission[i].Hard[Mission_PrimaryBooster] - 1; } Data->P[plr].Mission[i + 1].Hard[Mission_PrimaryBooster] = rck[1] + 1; } } } // JOINT MISSION KLUGGE MISSION 55 & 56 if (Data->P[plr].Mission[0].MissionCode == 55) { Data->P[plr].Mission[1].Hard[Mission_Capsule] = Data->P[plr].Mission[1].Prog - 1; Data->P[plr].Mission[0].Hard[Mission_LM] = 6; // LM Data->P[plr].Mission[0].Hard[Mission_Probe_DM] = 4; // DM Data->P[plr].Misc[1].Safety = maxx(Data->P[plr].Misc[1].Safety, Data->P[plr].Misc[1].MaxRD); Data->P[plr].Mission[1].Hard[Mission_Kicker] = 1; // kicker second part }; if (Data->P[plr].Mission[0].MissionCode == 56) { Data->P[plr].Mission[1].Hard[Mission_Capsule] = Data->P[plr].Mission[1].Prog - 1; Data->P[plr].Mission[0].Hard[Mission_LM] = 6; // LM Data->P[plr].Mission[0].Hard[Mission_Probe_DM] = 4; // DM Data->P[plr].Misc[1].Safety = maxx(Data->P[plr].Misc[1].Safety, Data->P[plr].Misc[1].MaxRD); Data->P[plr].Mission[0].Hard[Mission_Kicker] = 1; Data->P[plr].Mission[1].Hard[Mission_Kicker] = 1; }; // lunar module klugge for (i = 0; i < 3; i++) if (Data->P[plr].Mission[i].Hard[Mission_LM] >= 5) { Data->P[plr].Mission[i].Hard[Mission_LM] = Data->P[plr].Manned[5].Safety >= Data->P[plr].Manned[6].Safety ? 5 : 6; } JR = 0; k = 0; for (l = 0; l < 3; l++) { if (Data->P[plr].Mission[l].Joint == 1) { JR = 1; } if (Data->P[plr].Mission[l].MissionCode > 0 && Data->P[plr].Mission[l].part == 0) { k++; } Data->P[plr].Mission[l].Rushing = 0; // Clear Data } if (k == 3) { // Three non joint missions Data->P[plr].Mission[0].Month = 2 + Data->Season * 6; Data->P[plr].Mission[1].Month = 3 + Data->Season * 6; Data->P[plr].Mission[2].Month = 4 + Data->Season * 6; }; if (k == 2 && JR == 0) { // Two non joint missions l = 3; if (Data->P[plr].Mission[0].MissionCode > 0) { Data->P[plr].Mission[0].Month = l + Data->Season * 6; l += 2; }; if (Data->P[plr].Mission[1].MissionCode > 0) { Data->P[plr].Mission[1].Month = l + Data->Season * 6; l += 2; }; if (Data->P[plr].Mission[2].MissionCode > 0) { Data->P[plr].Mission[2].Month = l + Data->Season * 6; } }; if (k == 1 && JR == 0) { // Single Mission Non joint if (Data->P[plr].Mission[0].MissionCode > 0) { Data->P[plr].Mission[0].Month = 4 + Data->Season * 6; } if (Data->P[plr].Mission[1].MissionCode > 0) { Data->P[plr].Mission[1].Month = 4 + Data->Season * 6; } if (Data->P[plr].Mission[2].MissionCode > 0) { Data->P[plr].Mission[2].Month = 4 + Data->Season * 6; } }; if (k == 2 && JR == 1) { // Two launches, one Joint; if (Data->P[plr].Mission[1].part == 1) { // Joint first Data->P[plr].Mission[0].Month = 3 + Data->Season * 6; Data->P[plr].Mission[1].Month = 3 + Data->Season * 6; Data->P[plr].Mission[2].Month = 5 + Data->Season * 6; }; if (Data->P[plr].Mission[2].part == 1) { // Joint second Data->P[plr].Mission[0].Month = 3 + Data->Season * 6; Data->P[plr].Mission[1].Month = 5 + Data->Season * 6; Data->P[plr].Mission[2].Month = 5 + Data->Season * 6; }; }; if (k == 1 && JR == 1) { // Single Joint Launch if (Data->P[plr].Mission[1].part == 1) { // found on pad 1+2 Data->P[plr].Mission[0].Month = 4 + Data->Season * 6; Data->P[plr].Mission[1].Month = 4 + Data->Season * 6; } else { // found on pad 2+3 Data->P[plr].Mission[1].Month = 4 + Data->Season * 6; Data->P[plr].Mission[2].Month = 4 + Data->Season * 6; }; } return; }
void AIFuture(char plr, char mis, char pad, char *prog) { int i, j; char prime, back, max, men; char fake_prog[2]; if (prog == NULL) { memset(fake_prog, 0, sizeof fake_prog); prog = fake_prog; } GetMisType(mis); for (i = 0; i < (Mis.Jt + 1); i++) { Data->P[plr].Future[pad + i].MissionCode = mis; Data->P[plr].Future[pad + i].part = i; // duration if (Data->P[plr].DurLevel <= 5 && Data->P[plr].Future[pad + i].Duration == 0) { if (Mis.Dur == 1) Data->P[plr].Future[pad + i].Duration = maxx(Mis.Days, minn(Data->P[plr].DurLevel + 1, 6)); else { Data->P[plr].Future[pad + i].Duration = Mis.Days; } } if (Data->P[plr].Mission[0].Duration == Data->P[plr].Future[pad + i].Duration || Data->P[plr].Mission[1].Duration == Data->P[plr].Future[pad + i].Duration) { ++Data->P[plr].Future[pad + i].Duration; } if (pad == 1 && Data->P[plr].Future[0].Duration == Data->P[plr].Future[pad + i].Duration) { ++Data->P[plr].Future[pad + i].Duration; } if (Data->P[plr].Future[pad + i].Duration >= 6) { Data->P[plr].Future[pad + i].Duration = 6; } // one man capsule duration klugge if (Data->P[plr].Future[pad + i].Prog == 1) { if (Data->P[plr].DurLevel == 0) { Data->P[plr].Future[pad + i].Duration = 1; } else { Data->P[plr].Future[pad + i].Duration = 2; } }; // limit duration 'C' one man capsule // lunar mission klugge if (Mis.Lun == 1 || Data->P[plr].Future[pad + i].MissionCode == 55 || Data->P[plr].Future[pad + i].MissionCode == 56 || Data->P[plr].Future[pad + i].MissionCode == 53) { Data->P[plr].Future[pad + i].Duration = 4; } // unmanned duration klugge if (Mis.Days == 0) { Data->P[plr].Future[pad + i].Duration = 0; } Data->P[plr].Future[pad + i].Joint = Mis.Jt; Data->P[plr].Future[pad + i].Month = 0; if (mis == 1) { prog[i] = 0; } Data->P[plr].Future[pad + i].Prog = prog[0]; if (prog[i] > 0 && Mis.Days > 0) { for (j = 1; j < 6; j++) { DumpAstro(plr, j); } TransAstro(plr, prog[i]); //indexed OK if (Data->P[plr].Future[pad + i].PCrew != 0) { prime = Data->P[plr].Future[pad + i].PCrew - 1; } else { prime = -1; } if (Data->P[plr].Future[pad + i].BCrew != 0) { back = Data->P[plr].Future[pad + i].BCrew - 1; } else { back = -1; } max = prog[i]; if (prog[i] > 3) { max = prog[i] - 1; } Data->P[plr].Future[pad + i].Men = max; men = Data->P[plr].Future[pad + i].Men; if (prime != -1) for (j = 0; j < men; j++) { Data->P[plr].Pool[Data->P[plr].Crew[prog[i]][prime][j] - 1].Prime = 0; } if (back != -1) for (j = 0; j < men; j++) { Data->P[plr].Pool[Data->P[plr].Crew[prog[i]][back][j] - 1].Prime = 0; } Data->P[plr].Future[pad + i].PCrew = 0; Data->P[plr].Future[pad + i].BCrew = 0; pc[i] = -1; bc[i] = -1; for (j = 0; j < 8; j++) if (pc[i] == -1 && Data->P[plr].Crew[prog[i]][j][0] != 0 && Data->P[plr].Pool[Data->P[plr].Crew[prog[i]][j][0] - 1].Prime == 0) { pc[i] = j; } if (pc[i] == -1) { // astronaut/duration klugge if (Mis.Days > 0) { Data->P[plr].Future[pad + i].Men = max; } // no astronauts available have to go unmanned Data->P[plr].Future[pad + i].Men = 0; Data->P[plr].Future[pad + i].PCrew = 0; Data->P[plr].Future[pad + i].BCrew = 0; return; } Data->P[plr].Future[pad + i].PCrew = pc[i] + 1; bc[i] = -1; for (j = 0; j < 8; j++) if (bc[i] == -1 && j != pc[i] && Data->P[plr].Crew[prog[i]][j][0] != 0 && Data->P[plr].Pool[Data->P[plr].Crew[prog[i]][j][0] - 1].Prime == 0) { bc[i] = j; } Data->P[plr].Future[pad + i].BCrew = bc[i] + 1; for (j = 0; j < men; j++) { Data->P[plr].Pool[Data->P[plr].Crew[prog[i]][pc[i]][j] - 1].Prime = 4; } for (j = 0; j < men; j++) { Data->P[plr].Pool[Data->P[plr].Crew[prog[i]][bc[i]][j] - 1].Prime = 2; } } else { Data->P[plr].Future[pad + i].Men = 0; Data->P[plr].Future[pad + i].PCrew = 0; Data->P[plr].Future[pad + i].BCrew = 0; } } // joint mission 55 and 56 men klugge if (mis == 55 || mis == 56) { Data->P[plr].Future[pad + 1].Men = Data->P[plr].Future[pad].Men; Data->P[plr].Future[pad + 1].PCrew = Data->P[plr].Future[pad].PCrew; Data->P[plr].Future[pad + 1].BCrew = Data->P[plr].Future[pad].BCrew; Data->P[plr].Future[pad + 1].Prog = Data->P[plr].Future[pad].Prog; Data->P[plr].Future[pad].Men = 0; Data->P[plr].Future[pad].PCrew = 0; Data->P[plr].Future[pad].BCrew = 0; Data->P[plr].Future[pad].Prog = 0; Data->P[plr].Future[pad + 1].Duration = Data->P[plr].Future[pad].Duration; Data->P[plr].Future[pad].Duration = 0; } return; }
void dy_initbasis (int concnt, int factor, double zero_tol) /* This routine calls the glpk routine inv_create to initialize the basis data structures, then sets values for the zero tolerance (eps_tol), pivot ratio (piv_tol) and number of candidates examined (piv_lim). NOTE: This routine can be (and typically is) called before any of the main dylp data structures exist. Be careful what you reference. Parameters: concnt: the number of constraints (rows) that the basis representation should be capable of handling factor: the planned refactorisation frequency; passed to glpk as the basis inverse update capacity (i.e., the limit on the number of pivots between refactorisations) zero_tol: zero tolerance; a value of 0.0 uses the glpk default (INV->LUF->eps_tol = 1.0e-15). Returns: void */ { int sva_size ; const char *rtnnme = "dy_initbasis" ; /* Create the basis. Allow for at least five constraints (also handles pathological examples with no explicit constraints). */ luf_capacity = maxx(concnt,5) ; luf_basis = inv_create(luf_capacity,factor) ; if (luf_basis == NULL) { if (dy_lp == NULL) { errmsg(302,rtnnme,"empty","pre-init",0,"create") ; } else { errmsg(302,rtnnme,dy_sys->nme,dy_prtlpphase(dy_lp->phase,TRUE), dy_lp->tot.iters,"create") ; } return ; } /* WARNING: We're going to reach inside glpluf to get it to triple the amount of space that it allocates for the sparse vector area. We're doing this by triggering the reallocation mechanism built into luf_decomp (called by inv_decomp). */ sva_size = luf_basis->luf->sv_size ; luf_basis->luf->new_sva = 3*sva_size ; # ifndef DYLP_NDEBUG if (dy_opts != NULL && dy_opts->print.basis >= 2) { dyio_outfmt(dy_logchn,dy_gtxecho, "\ninitbasis: %s(%d) basis capacity %d, piv lim %d.", dy_prtlpphase(dy_lp->phase,TRUE),dy_lp->tot.iters, luf_basis->luf->n,luf_basis->hh_max) ; } /* XX_DEBUG_XX There's no good way to control this output, given the timing of the call (before dy_opts is initialised), but it's sometimes useful when debugging. else { dyio_outfmt(dy_logchn,TRUE, "\ninitbasis: EXTERN(0) basis capacity %d, piv lim %d.", luf_basis->luf->n,luf_basis->hh_max) ; } */ # endif /* Set the initial pivot level to {.01,4}, and allow it to drop to {.01,4}. */ pivlevel = 0 ; minpivlevel = 0 ; if (zero_tol != 0.0) luf_basis->luf->eps_tol = zero_tol ; luf_basis->luf->piv_tol = pivtols[pivlevel].stable ; luf_basis->luf->piv_lim = pivtols[pivlevel].look ; luf_basis->luf->max_gro = 1.0e7 ; /* This is the smallest value that can appear on the diagonal of U after a pivot update. dylp will (in extremis) drop its pivot selection tolerance tols.pivot to 1e-9 (or thereabouts), so upd_tol had better be less or we spend a lot of time refactoring. This should probably be adjusted as needed, in response to adjustments in tols.pivot, but I need to sit down and really think about the math. In the meantime, this seems to be adequate. */ luf_basis->upd_tol = 1.0e-10 ; return ; }
void dy_setprintopts (int lvl, lpopts_struct *opts) /* This routine tweaks the lp print level options based on a single integer code. It's intended to allow clients of dylp to easily set up overall print levels. Just a big case statement. Level 0 forces dylp to shut up. Level 1 assumes the normal dylp defaults (phase1, phase2, dual, force, and basis print levels set to 1, which allows messages about extraordinary events). Levels 2 -- 5 provide increasing amounts of information. At level 1 and above, a specific setting of a dylp value to a higher value in the options structure passed in as a parameter will override the value here. Parameters: lvl: overall print level opts: options structure; for all except lvl = 0, should be preloaded with valid values for print options. Returns: undefined */ { if (lvl < 0) lvl = 0 ; switch (lvl) { case 0: { opts->print.major = 0 ; opts->print.scaling = 0 ; opts->print.setup = 0 ; opts->print.crash = 0 ; opts->print.pricing = 0 ; opts->print.pivoting = 0 ; opts->print.pivreject = 0 ; opts->print.degen = 0 ; opts->print.phase1 = 0 ; opts->print.phase2 = 0 ; opts->print.dual = 0 ; opts->print.basis = 0 ; opts->print.conmgmt = 0 ; opts->print.varmgmt = 0 ; opts->print.force = 0 ; opts->print.tableau = 0 ; opts->print.rays = 0 ; opts->print.soln = 0 ; break ; } case 1: { opts->print.major = maxx(opts->print.major,dyopts_dflt.print.major) ; opts->print.scaling = maxx(opts->print.scaling,dyopts_dflt.print.scaling) ; opts->print.setup = maxx(opts->print.setup,dyopts_dflt.print.setup) ; opts->print.crash = maxx(opts->print.crash,dyopts_dflt.print.crash) ; opts->print.pricing = maxx(opts->print.pricing, dyopts_dflt.print.pricing) ; opts->print.pivoting = maxx(opts->print.pivoting, dyopts_dflt.print.pivoting) ; opts->print.pivreject = maxx(opts->print.pivreject, dyopts_dflt.print.pivreject) ; opts->print.degen = maxx(opts->print.degen,dyopts_dflt.print.degen) ; opts->print.phase1 = maxx(opts->print.phase1,dyopts_dflt.print.phase1) ; opts->print.phase2 = maxx(opts->print.phase2,dyopts_dflt.print.phase2) ; opts->print.dual = maxx(opts->print.dual,dyopts_dflt.print.dual) ; opts->print.basis = maxx(opts->print.basis,dyopts_dflt.print.basis) ; opts->print.conmgmt = maxx(opts->print.conmgmt, dyopts_dflt.print.conmgmt) ; opts->print.varmgmt = maxx(opts->print.varmgmt, dyopts_dflt.print.varmgmt) ; opts->print.force = maxx(opts->print.force,dyopts_dflt.print.force) ; opts->print.tableau = maxx(opts->print.tableau, dyopts_dflt.print.tableau) ; opts->print.rays = maxx(opts->print.rays, dyopts_dflt.print.rays) ; opts->print.soln = maxx(opts->print.soln, dyopts_dflt.print.soln) ; break ; } case 2: { opts->print.major = maxx(opts->print.major,1) ; opts->print.scaling = maxx(opts->print.scaling,1) ; opts->print.setup = maxx(opts->print.setup,1) ; opts->print.crash = maxx(opts->print.crash,1) ; opts->print.pricing = maxx(opts->print.pricing,0) ; opts->print.pivoting = maxx(opts->print.pivoting,0) ; opts->print.pivreject = maxx(opts->print.pivreject,0) ; opts->print.degen = maxx(opts->print.degen,1) ; opts->print.phase1 = maxx(opts->print.phase1,1) ; opts->print.phase2 = maxx(opts->print.phase2,1) ; opts->print.dual = maxx(opts->print.dual,1) ; opts->print.basis = maxx(opts->print.basis,1) ; opts->print.conmgmt = maxx(opts->print.conmgmt,1) ; opts->print.varmgmt = maxx(opts->print.varmgmt,1) ; opts->print.force = maxx(opts->print.force,1) ; opts->print.tableau = maxx(opts->print.tableau,1) ; opts->print.rays = maxx(opts->print.rays,1) ; opts->print.soln = maxx(opts->print.soln,1) ; break ; } case 3: { opts->print.major = maxx(opts->print.major,1) ; opts->print.scaling = maxx(opts->print.scaling,2) ; opts->print.setup = maxx(opts->print.setup,2) ; opts->print.crash = maxx(opts->print.crash,2) ; opts->print.pricing = maxx(opts->print.pricing,0) ; opts->print.pivoting = maxx(opts->print.pivoting,0) ; opts->print.pivreject = maxx(opts->print.pivreject,0) ; opts->print.degen = maxx(opts->print.degen,1) ; opts->print.phase1 = maxx(opts->print.phase1,3) ; opts->print.phase2 = maxx(opts->print.phase2,3) ; opts->print.dual = maxx(opts->print.dual,3) ; opts->print.basis = maxx(opts->print.basis,2) ; opts->print.conmgmt = maxx(opts->print.conmgmt,2) ; opts->print.varmgmt = maxx(opts->print.varmgmt,2) ; opts->print.force = maxx(opts->print.force,1) ; opts->print.tableau = maxx(opts->print.tableau,1) ; opts->print.rays = maxx(opts->print.rays,1) ; opts->print.soln = maxx(opts->print.soln,1) ; break ; } case 4: { opts->print.major = maxx(opts->print.major,1) ; opts->print.scaling = maxx(opts->print.scaling,2) ; opts->print.setup = maxx(opts->print.setup,3) ; opts->print.crash = maxx(opts->print.crash,3) ; opts->print.pricing = maxx(opts->print.pricing,0) ; opts->print.pivoting = maxx(opts->print.pivoting,0) ; opts->print.pivreject = maxx(opts->print.pivreject,0) ; opts->print.degen = maxx(opts->print.degen,2) ; opts->print.phase1 = maxx(opts->print.phase1,4) ; opts->print.phase2 = maxx(opts->print.phase2,4) ; opts->print.dual = maxx(opts->print.dual,4) ; opts->print.basis = maxx(opts->print.basis,3) ; opts->print.conmgmt = maxx(opts->print.conmgmt,3) ; opts->print.varmgmt = maxx(opts->print.varmgmt,2) ; opts->print.force = maxx(opts->print.force,2) ; opts->print.tableau = maxx(opts->print.tableau,1) ; opts->print.rays = maxx(opts->print.rays,3) ; opts->print.soln = maxx(opts->print.soln,3) ; break ; } default: { opts->print.major = maxx(opts->print.major,1) ; opts->print.scaling = maxx(opts->print.scaling,2) ; opts->print.setup = maxx(opts->print.setup,5) ; opts->print.crash = maxx(opts->print.crash,4) ; opts->print.pricing = maxx(opts->print.pricing,1) ; opts->print.pivoting = maxx(opts->print.pivoting,1) ; opts->print.pivreject = maxx(opts->print.pivreject,1) ; opts->print.degen = maxx(opts->print.degen,2) ; opts->print.phase1 = maxx(opts->print.phase1,5) ; opts->print.phase2 = maxx(opts->print.phase2,5) ; opts->print.dual = maxx(opts->print.dual,5) ; opts->print.basis = maxx(opts->print.basis,5) ; opts->print.conmgmt = maxx(opts->print.conmgmt,3) ; opts->print.varmgmt = maxx(opts->print.varmgmt,2) ; opts->print.force = maxx(opts->print.force,3) ; opts->print.tableau = maxx(opts->print.tableau,4) ; opts->print.rays = maxx(opts->print.rays,4) ; opts->print.soln = maxx(opts->print.soln,4) ; break ; } } return ; }
void dy_checkdefaults (consys_struct *sys, lpopts_struct *opts, lptols_struct *tols) /* This routine looks over various option and tolerance settings with an eye toward setting or adjusting values based on the size of the constraint system or other options that might be set by the user. The default values here are, by and large, grossly larger than required. The more outrageous ones are motivated by the Netlib examples. Parameters: sys: a constraint system opts: an options structure; may be modified on return Returns: undefined */ { int scalefactor ; if (opts->check < 0) opts->check = opts->factor/2 ; if (opts->check <= 0) opts->check = 1 ; if (opts->scan < 0) { opts->scan = maxx(dyopts_lb.scan,sys->archvcnt/2) ; opts->scan = minn(opts->scan,dyopts_ub.scan) ; } if (opts->iterlim < 0) { opts->iterlim = minn(5*(sys->concnt+sys->varcnt),100000) ; opts->iterlim = maxx(opts->iterlim,10000) ; } if (opts->idlelim < 0) { opts->idlelim = minn(2*(sys->concnt+sys->varcnt),50000) ; opts->idlelim = maxx(opts->idlelim,1000) ; } if (opts->degenpivlim < 0) { opts->degenpivlim = minn(1000,sys->concnt/2) ; opts->degenpivlim = maxx(100,opts->degenpivlim) ; } /* If the user has specified a dual pivot strategy, observe it. If not, start with strategy 1 (max dual objective improvement). */ if (opts->dpsel.strat >= 0) { opts->dpsel.flex = FALSE ; } else { opts->dpsel.strat = 1 ; opts->dpsel.flex = TRUE ; } if (opts->fullsys == TRUE) { opts->active.vars = 1.0 ; opts->active.cons = 1.0 ; } /* Loosen the base primal and dual accuracy check values for larger systems, and put a little more distance between the zero tolerances and feasibility tolerances. */ scalefactor = ((int) (.5 + log10((double) sys->varcnt))) - 2 ; if (scalefactor > 0) { tols->pchk *= pow(10.0,(double) scalefactor) ; tols->pfeas_scale *= pow(10.0,(double) scalefactor) ; } scalefactor = ((int) (.5 + log10((double) sys->concnt))) - 2 ; if (scalefactor > 0) { tols->dchk *= pow(10.0,(double) scalefactor) ; tols->dfeas_scale *= pow(10.0,(double) scalefactor) ; } /* XX_DEBUG_XX There's no good way to control this print statement, given the timing and purpose of this call. But it's occasionally handy for debugging. dyio_outfmt(dy_logchn,TRUE,"\nPTOLS: pzero = %g, pscale = %g, pchk = %g", tols->zero,tols->pfeas_scale,tols->pchk) ; dyio_outfmt(dy_logchn,TRUE,"\nDTOLS: dzero = %g, dscale = %g, dchk = %g", tols->cost,tols->dfeas_scale,tols->dchk) ; */ return ; }
int main (int argc, char** argv) { //using namespace mapnik; namespace po = boost::program_options; bool verbose = false; bool validate_features = false; unsigned int depth = DEFAULT_DEPTH; double ratio = DEFAULT_RATIO; std::vector<std::string> files; char separator = 0; char quote = 0; std::string manual_headers; try { po::options_description desc("Mapnik CSV/GeoJSON index utility"); desc.add_options() ("help,h", "produce usage message") ("version,V","print version string") ("verbose,v","verbose output") ("depth,d", po::value<unsigned int>(), "max tree depth\n(default 8)") ("ratio,r",po::value<double>(),"split ratio (default 0.55)") ("separator,s", po::value<char>(), "CSV columns separator") ("quote,q", po::value<char>(), "CSV columns quote") ("manual-headers,H", po::value<std::string>(), "CSV manual headers string") ("files",po::value<std::vector<std::string> >(),"Files to index: file1 file2 ...fileN") ("validate-features", "Validate GeoJSON features") ; po::positional_options_description p; p.add("files",-1); po::variables_map vm; po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm); po::notify(vm); if (vm.count("version")) { std::clog << "version 1.0.0" << std::endl; return 1; } if (vm.count("help")) { std::clog << desc << std::endl; return 1; } if (vm.count("verbose")) { verbose = true; } if (vm.count("validate-features")) { validate_features = true; } if (vm.count("depth")) { depth = vm["depth"].as<unsigned int>(); } if (vm.count("ratio")) { ratio = vm["ratio"].as<double>(); } if (vm.count("separator")) { separator = vm["separator"].as<char>(); } if (vm.count("quote")) { quote = vm["quote"].as<char>(); } if (vm.count("manual-headers")) { manual_headers = vm["manual-headers"].as<std::string>(); } if (vm.count("files")) { files=vm["files"].as<std::vector<std::string> >(); } } catch (std::exception const& ex) { std::clog << "Error: " << ex.what() << std::endl; return EXIT_FAILURE; } std::vector<std::string> files_to_process; for (auto const& filename : files) { if (!mapnik::util::exists(filename)) { continue; } if (mapnik::detail::is_csv(filename) || mapnik::detail::is_geojson(filename)) { files_to_process.push_back(filename); } } if (files_to_process.size() == 0) { std::clog << "no files to index" << std::endl; return EXIT_FAILURE; } std::clog << "max tree depth:" << depth << std::endl; std::clog << "split ratio:" << ratio << std::endl; using box_type = mapnik::box2d<float>; using item_type = std::pair<box_type, std::pair<std::size_t, std::size_t>>; for (auto const& filename : files_to_process) { if (!mapnik::util::exists(filename)) { std::clog << "Error : file " << filename << " does not exist" << std::endl; continue; } std::vector<item_type> boxes; box_type extent; if (mapnik::detail::is_csv(filename)) { std::clog << "processing '" << filename << "' as CSV\n"; auto result = mapnik::detail::process_csv_file(boxes, filename, manual_headers, separator, quote); if (!result.first) continue; extent = result.second; } else if (mapnik::detail::is_geojson(filename)) { std::clog << "processing '" << filename << "' as GeoJSON\n"; auto result = mapnik::detail::process_geojson_file(boxes, filename, validate_features, verbose); if (!result.first) { std::clog << "Error: failed to process " << filename << std::endl; continue; } extent = result.second; } if (extent.valid()) { std::clog << extent << std::endl; mapnik::box2d<double> extent_d(extent.minx(), extent.miny(), extent.maxx(), extent.maxy()); mapnik::quad_tree<std::pair<std::size_t, std::size_t>> tree(extent_d, depth, ratio); for (auto const& item : boxes) { auto ext_f = std::get<0>(item); tree.insert(std::get<1>(item), mapnik::box2d<double>(ext_f.minx(), ext_f.miny(), ext_f.maxx(), ext_f.maxy())); } std::fstream file((filename + ".index").c_str(), std::ios::in | std::ios::out | std::ios::trunc | std::ios::binary); if (!file) { std::clog << "cannot open index file for writing file \"" << (filename + ".index") << "\"" << std::endl; } else { tree.trim(); std::clog << "number nodes=" << tree.count() << std::endl; std::clog << "number element=" << tree.count_items() << std::endl; file.exceptions(std::ios::failbit | std::ios::badbit); tree.write(file); file.flush(); file.close(); } } } std::clog << "done!" << std::endl; return EXIT_SUCCESS; }
int EmbedVision(TopologicalGraph &G) {int morg = G.ne(); if(!G.CheckConnected())G.MakeConnected(); if(!G.FindPlanarMap()) {Tprintf("Not Planar Graph"); for(tedge e = G.ne(); e > morg; e--) G.DeleteEdge(e); return -1; } if(!G.CheckBiconnected())G.Biconnect(); bool alreadyBipolarOriented = false; bool stConnected = false; tvertex s,t; tbrin bs,bt; bool already2Connected = (morg == G.ne()); if(already2Connected && (alreadyBipolarOriented = CheckBipolarlyOriented(G,s,t,stConnected,bs,true)) == true) {if(stConnected)Tprintf("Using original orientation (s,t are connected)"); else Tprintf("Using original orientation (s,t are not connected)"); bt = -bs; } else {// Find reasonable s t vertices tedge e; tbrin b; int len; G.LongestFace(bs,len); s = G.vin[bs]; bt = bs; for(int i = 1 ;i <= len/2; i++)bt = G.cir[-bt]; t = G.vin[bt]; // Check if s an t are connected b = bs; do {if(G.vin[-b] == t){stConnected = true;break;} }while((b = G.cir[b]) != bs); if(!stConnected) {G.NewEdge(bs,bt); bs = (tbrin)G.ne(); } s = G.vin[bs]; t = G.vin[-bs]; // BipolarOrient the graph G.BipolarPlan(bs); G.FixOrientation(); } int n = G.nv(); int m = G.ne(); // if bs has been reoriented as the packing suppose that vin[bst]= source tbrin bst = (G.vin[bs] != s) ? -bs : bs; // Compute y coords Prop<int> y(G.Set(tvertex()),PROP_DRAW_INT_5); y.clear(); MaxPath *MP=new MaxPath(n,m); for(tedge e = 1; e <= m; e++) MP->insert(G.vin[e.firsttbrin()](),G.vin[e.secondtbrin()](),1); MP->solve(y); delete MP; int maxyval = y[t]; // compute MaxPath for edges svector<int> x(0,m); x.clear(); MP=new MaxPath(m,2*m); svector<tbrin> &Fpbrin = G.ComputeFpbrin(); tbrin b0,b; // out == positif for(int i = 1; i <= Fpbrin.n(); i++) {b0 = Fpbrin[i]; if(b0.out()) while((b=-G.acir[b0]).out()) b0=b; else do {b0=G.cir[-b0];} while(b0.in()); // b0 is the lowest tbrin on the left of the face if(b0 == G.cir[bst])continue; // face exterieure // référence : e tedge e = (G.acir[b0]).GetEdge(); b=b0; while (b.out()) {if(stConnected || b != bst) MP->insert(b.GetEdge()(),e(),1); b=G.cir[-b]; } while (b.GetEdge()!=e) {MP->insert(e(),b.GetEdge()(),0); b=G.cir[-b]; } } MP->solve(x); delete &Fpbrin; delete MP; // computes extremities of vertices Prop<int> x1(G.Set(tvertex()),PROP_DRAW_INT_1); Prop<int> x2(G.Set(tvertex()),PROP_DRAW_INT_2); int maxxval=ComputeExtremities(G,x,x1,x2,morg); Prop1<int> m_org(G.Set(),PROP_TMP); m_org() = morg; for(tedge e = G.ne(); e > morg; e--) G.DeleteEdge(e); Prop1<int> maxx(G.Set(),PROP_DRAW_INT_1); Prop1<int> maxy(G.Set(),PROP_DRAW_INT_2); maxx()=maxxval; maxy()=maxyval; Prop1<Tpoint> pmin(G.Set(),PROP_POINT_MIN); Prop1<Tpoint> pmax(G.Set(),PROP_POINT_MAX); pmin() = Tpoint(-1,-1); pmax() = Tpoint(maxxval+1,maxyval+1); Prop<Tpoint> P1(G.Set(tedge()),PROP_DRAW_POINT_1); Prop<Tpoint> P2(G.Set(tedge()),PROP_DRAW_POINT_2); for (tedge e=1; e<= G.ne(); e++) {P1[e]=Tpoint(x[e],y[G.vin[e.firsttbrin()]]); P2[e]=Tpoint(x[e],y[G.vin[e.secondtbrin()]]); } return 0; }
/** * Calculate and return the center */ PRECISION get_xcenter() const { return (maxx() + minx()) / 2; }