void readFile( FILE * f ) { char ** lines = NULL; char * curr = NULL; size_t sz; size_t i = 0; while( getline(&curr,&sz,f) >=0 ) { lines = realloc(lines,(i+1) * sizeof(*lines)); lines[i] = curr; curr = NULL; i++; } free(curr); sortData(lines,i); for( size_t j = 0; j < i; j++ ) { printf("%s",lines[j]); free(lines[j]); } free(lines); }
void CBOINCBaseView::SetSortColumn(int newSortColIndex) { wxListItem item; int i, j, m; wxArrayInt selections; item.SetImage(m_bReverseSort ? 0 : 1); m_pListPane->SetColumn(newSortColIndex, item); Freeze(); // To reduce flicker // Remember which cache elements are selected and deselect them m_bIgnoreUIEvents = true; i = -1; while (1) { i = m_pListPane->GetNextSelected(i); if (i < 0) break; selections.Add(m_iSortedIndexes[i]); m_pListPane->SelectRow(i, false); } sortData(); // Reselect previously selected cache elements in the sorted list m = (int)selections.GetCount(); for (i=0; i<m; i++) { if (selections[i] >= 0) { j = m_iSortedIndexes.Index(selections[i]); m_pListPane->SelectRow(j, true); } } m_bIgnoreUIEvents = false; Thaw(); }
void Repository::loadFromFile(string file){ ifstream f("/Users/AndiD/Documents/C++/exam_retake/progs.txt"); string line; while (getline(f, line)) { stringstream ss(line); vector <string> tokens; string token; while(getline(ss, token, '|')) { tokens.push_back(token); } string name=tokens[0]; int id = stoi(tokens[1]); Programmer p(name, id); prog.push_back(p); } f.close(); f.open(file); while (getline(f, line)) { stringstream ss(line); vector <string> tokens; string token; while (getline(ss, token, '|')) { tokens.push_back(token); } if (tokens.size() < 3) tokens.push_back("-1"); Task t(tokens[0], tokens[1], stoi(tokens[2])); task.push_back(t); } sortData(); }
QVariant IWFileTreeModel::data(const QModelIndex & index, int role) const { Node* n = 0; if (index.column() < 2 && role != Qt::ForegroundRole) return TorrentFileTreeModel::data(index,role); if (!index.isValid() || !(n = (Node*)index.internalPointer())) return QVariant(); if (role == Qt::ForegroundRole && index.column() == 2 && tc->getStats().multi_file_torrent && n->file) { const bt::TorrentFileInterface* file = n->file; switch (file->getPriority()) { /*case FIRST_PRIORITY: return InfoWidgetPluginSettings::firstColor(); case LAST_PRIORITY: return InfoWidgetPluginSettings::lastColor(); case NORMAL_PRIORITY: return InfoWidgetPluginSettings::normalColor(); case ONLY_SEED_PRIORITY: case EXCLUDED: case PREVIEW_PRIORITY: default:*/ return QVariant(); } } if (role == Qt::DisplayRole) return displayData(n,index); else if (role == Qt::UserRole) return sortData(n,index); return QVariant(); }
QVariant IWFileListModel::data(const QModelIndex& index, int role) const { if (index.column() < 2 && role != Qt::ForegroundRole) return TorrentFileListModel::data(index, role); if (!tc || !index.isValid() || index.row() >= rowCount(QModelIndex())) return QVariant(); if (role == Qt::ForegroundRole && index.column() == 2 && tc->getStats().multi_file_torrent) { const bt::TorrentFileInterface* file = &tc->getTorrentFile(index.row()); switch (file->getPriority()) { case FIRST_PRIORITY: return InfoWidgetPluginSettings::firstColor(); case LAST_PRIORITY: return InfoWidgetPluginSettings::lastColor(); case NORMAL_PRIORITY: return QVariant(); case ONLY_SEED_PRIORITY: case EXCLUDED: case PREVIEW_PRIORITY: default: return QVariant(); } } if (role == Qt::DisplayRole) return displayData(index); else if (role == Qt::UserRole) return sortData(index); return QVariant(); }
int main(void) { sortData(data, LENGTH); printData(data, LENGTH); return 0; }
void Repository::modifyTask(const int & oldID, const int& newID, const string &progress) { for( auto it=task.begin(); it!= task.end(); it++){ if( (*it).getTaskId() == oldID){ (*it).setId(newID); (*it).setStatus(progress); } } sortData(); notify(); }
void CBOINCBaseView::InitSort() { wxListItem item; if (m_iSortColumn < 0) return; item.SetMask(wxLIST_MASK_IMAGE); item.SetImage(m_bReverseSort ? 0 : 1); m_pListPane->SetColumn(m_iSortColumn, item); Freeze(); // To reduce flicker sortData(); Thaw(); }
int HumInstrument::setGM(const string& Hname, int aValue) { if (aValue < 0 || aValue > 127) { return 0; } int rindex = find(Hname); if (rindex > 0) { data[rindex].gm = aValue; } else { afi(Hname.c_str(), aValue, Hname.c_str()); sortData(); } return rindex; }
void ICACHE_FLASH_ATTR saveData(char *location, char *device, char *sensor, char *type, char *value) { int slot; if ((slot = findEntry(location, device, sensor, type)) >= 0) { strcpy(valueEntries[slot].type, type); // Update Value strcpy(valueEntries[slot].val, value); } else if ((slot = findSlot()) >= 0) { //os_printf("Slot %d\n", slot); storeEntry(slot, location, device, sensor, type, value); sortData(); } else { // Loose it } }
void SM_ModelBackend::addSubnet(Subnet *subnet) { SubnetList.append(subnet); emit dataChanged(); if (subnet->isV4()) { Subnet4List.append(subnet); emit data4Changed(); } else { Subnet6List.append(subnet); emit data6Changed(); }; sortData(); }
void CBOINCBaseView::OnColClick(wxListEvent& event) { wxListItem item; int newSortColumn = event.GetColumn(); wxArrayInt selections; int i, j, m; item.SetMask(wxLIST_MASK_IMAGE); if (newSortColumn == m_iSortColumn) { m_bReverseSort = !m_bReverseSort; } else { // Remove sort arrow from old sort column if (m_iSortColumn >= 0) { item.SetImage(-1); m_pListPane->SetColumn(m_iSortColumn, item); } m_iSortColumn = newSortColumn; m_bReverseSort = false; } item.SetImage(m_bReverseSort ? 0 : 1); m_pListPane->SetColumn(newSortColumn, item); Freeze(); // To reduce flicker // Remember which cache elements are selected and deselect them m_bIgnoreUIEvents = true; i = -1; while (1) { i = m_pListPane->GetNextSelected(i); if (i < 0) break; selections.Add(m_iSortedIndexes[i]); m_pListPane->SelectRow(i, false); } sortData(); // Reselect previously selected cache elements in the sorted list m = (int)selections.GetCount(); for (i=0; i<m; i++) { if (selections[i] >= 0) { j = m_iSortedIndexes.Index(selections[i]); m_pListPane->SelectRow(j, true); } } m_bIgnoreUIEvents = false; Thaw(); }
uint16 Fsr::readRawValue() { uint16_t rawVal[numSamples]; for (uint16_t i = 0; i < numSamples; i++) { rawVal[i] = analogRead(analogPin); // read the dust value via pin 5 on the sensor delayMicroseconds(delayTime); } // now we have the raw values, sort them sortData(rawVal, numSamples); // drop the lowest 25% and highest 25% of the readings uint16_t value = 0; for (uint16_t i = numSamples / 4; i < (numSamples * 3 / 4); i++) { value += rawVal[i]; } value /= (numSamples / 2); return value; }
int CBOINCBaseView::SynchronizeCache() { int iRowIndex = 0; int iRowTotal = 0; int iColumnIndex = 0; int iColumnTotal = 0; bool bNeedRefreshData = false; iRowTotal = GetDocCount(); iColumnTotal = m_pListPane->GetColumnCount(); for (iRowIndex = 0; iRowIndex < iRowTotal; iRowIndex++) { bNeedRefreshData = false; for (iColumnIndex = 0; iColumnIndex < iColumnTotal; iColumnIndex++) { if (SynchronizeCacheItem(iRowIndex, iColumnIndex)) { #ifdef __WXMAC__ bNeedRefreshData = true; #else // To reduce flicker, refresh only changed columns m_pListPane->RefreshCell(iRowIndex, iColumnIndex); #endif if (iColumnIndex >= 0) { if (m_iColumnIndexToColumnID[iColumnIndex] == m_iSortColumnID) { m_bNeedSort = true; } } } } // Mac is double-buffered to avoid flicker, so this is more efficient if (bNeedRefreshData) { m_pListPane->RefreshItem(iRowIndex); } } if (m_bNeedSort) { sortData(); // Will mark moved items as needing refresh m_bNeedSort = false; } return 0; }
void parseSerialData() { char *p = buffer; // The data to be parsed char *str; // Temp store for each data chunk int counter = 0; // Id ref for each chunk while ((str = strtok_r(p, ":", &p)) != NULL)// Loop through the data and seperate it into chunks at each ":" delimeter { inParse[counter] = str;// Add chunk to array counter++; // Increment data count } char *chn = inParse[1]; char *red = inParse[2]; char *grn = inParse[3]; char *blu = inParse[4]; char *mode = inParse[5]; char *audB = inParse[6]; char *audS = inParse[7]; char *unic = inParse[8]; char *save = inParse[9]; sortData(chn,red,grn,blu,mode,audB,audS,unic,save); }
DWORD WINAPI computationThread_PC( LPVOID lpParam ){ // Buffer declarations long i ; long j ; for(;;){ GenerateTimeSample(); {//ComputeFFT init_inLoopPort_0(outLoopPort_0_inLo_0, 16/*init_size*/); trigger(); for(i = 0; i<8 ; i ++) {//cluster_0 char *outSub_i_out_clust_0 = &out_cluster_0_trig_0 [((i*(1))%8)]; sortData(dataOut_timeData, outLoopPort_0_inLo_0, outSub_i_out_clust_0, data1Out_data1In, data2Out_data2In, weights_W, 16/*size*/); for(j = 0; j<8 ; j ++) {//butterflyStep char *inSub_j_data1Out_d_0 = &data1Out_data1In_0 [((j*(1))%8)]; char *inSub_j_data2Out_d_0 = &data2Out_data2In_0 [((j*(1))%8)]; char *outSub_j_data1Out__0 = &data1Out_data1In [((j*(1))%8)]; char *outSub_j_data2Out__0 = &data2Out_data2In [((j*(1))%8)]; char *outSub_j_weights_W = &weights_W [((j*(1))%8)]; char *out_op2 = &res_in [((0*1)%1)]; char *out_op2_0 = &res_in [((0*1)%1)]; mult(outSub_j_data2Out__0, outSub_j_weights_W, res_in); add(outSub_j_data1Out__0, out_op2, inSub_j_data1Out_d_0); sub(outSub_j_data1Out__0, out_op2_0, inSub_j_data2Out_d_0); } collectData(data1Out_data1In_0, data2Out_data2In_0, dataOut_in, 16/*size*/); {//brSamples fftData_dataIn = &dataOut_in[0]; outLoopPort_0_inLo_0 = &dataOut_in[0]; } } } DisplayResult(); } return 0; }//computationThread
RobotCommand TacticPush2Goal::getCommand() { oppIsValid = wm->ourRobot[0].isValid;//wm->theirRobot.IsValid;// opposite robot addData(); sortData(); if(!oppIsValid) opp = Vector2D(1000000,1000000); opp = wm->ourRobot[0].pos.loc;//wm->theirRobot.position;//wm->ourRobot[8].pos.loc; OppIsKhoraak=!circularBorder2.contains(opp);//out of his field bool reach=false; Avoided=false; AllIn=true; AnyIn=false; AllInCorner=true; AllUnAccessible=true; RobotCommand rc; if(!wm->ourRobot[id].isValid) return rc; rc.fin_pos.loc=Vector2D(400,0);//circularBorder.center(); rc.maxSpeed = 1.2; index=-1; int tah=balls.size()-1; if(tah != -1) { rc.fin_pos.loc=circularBorder2.nearestpoint(balls.at(tah)->pos.loc); rc.fin_pos.dir=(circularBorder.center()-rc.fin_pos.loc).dir().radian(); } FindBall(); // find approtiate ball if( index != -1 ) { point2 = balls.at(index)->pos.loc; FindHole(); Vector2D nrstpnt = (circularBorder.center()-point2); //nearest Point nrstpnt=nrstpnt.setLength(nrstpnt.length()-circularBorder2.radius()); diff2 = nrstpnt; nrstpnt=point2+nrstpnt; // state2=0; switch(state) { case 0:{ //Go Behind the Object vec2goal.setLength(250); // qDebug()<<"VEC 2 GOAL LENGTH = " << vec2goal.length(); rc.maxSpeed=1.3; rc.useNav = false;//true; rc.isBallObs = false;//true; rc.isKickObs = false;//true; rc.fin_pos.loc=wm->kn->PredictDestination(wm->ourRobot[id].pos.loc,point2 - vec2goal, rc.maxSpeed,balls.at(index)->vel.loc);//point2 - vec2goal; // wm->kn->PredictDestination() int rad = 150+ROBOT_RADIUS; Circle2D c(point2,rad); rc.fin_pos.loc=AvoidtoEnterCircle(c,wm->ourRobot[id].pos.loc,rc.fin_pos.loc); // if(Avoided) rc.maxSpeed=rc.maxSpeed; rc.fin_pos.dir=vec2goal.dir().radian(); // KeepInField(rc); reach=wm->kn->ReachedToPos(wm->ourRobot[id].pos.loc,rc.fin_pos.loc,100); if(reach && !Avoided) state = 1; } break; case 1:{//Push rc.useNav = false; rc.isBallObs = false; rc.isKickObs = false; rc.maxSpeed=1.1; vec2goal.setLength(100); rc.fin_pos.loc=wm->kn->PredictDestination(wm->ourRobot[id].pos.loc,point2 + vec2goal, rc.maxSpeed,balls.at(index)->vel.loc); rc.fin_pos.dir=vec2goal.dir().radian(); KeepInField(rc); if(((wm->ourRobot[id].pos.loc-point2).length())>800) state=0; if(((wm->ourRobot[id].pos.loc-rc.fin_pos.loc).length())<250) state=0; if(hole1.contains(rc.fin_pos.loc) || hole2.contains(rc.fin_pos.loc)) { // vec2goal.setLength(100); rc.fin_pos.loc=point2 ;//+ vec2goal; // rc.fin_pos.loc=point2; } // reach=wm->kn->ReachedToPos(wm->ourRobot[id].pos.loc,rc.fin_pos.loc,40); // if(reach) // state2 = 0; } break; } int mrgn=200; Vector2D dlta; if(IsInmargins(point2,mrgn)) { int side = ((point2.x-mean_x)/abs(point2.x-mean_x))*((point2.y-mean_y)/abs(point2.y-mean_y)); if(point2.x > MAX_X-mrgn || point2.x < MIN_X+mrgn) { side *= ((point2.y-mean_y)/abs(point2.y-mean_y)); dlta=Vector2D(0,side*(ROBOT_RADIUS+20));} else if(point2.y > MAX_Y-mrgn || point2.y < MIN_Y+mrgn) { side *=((point2.x-mean_x)/abs(point2.x-mean_x)); dlta=Vector2D(side*(ROBOT_RADIUS+20),0);} switch(statemargin) { case 0:{ rc.fin_pos.loc=point2+dlta; int rad = 70+ROBOT_RADIUS; Circle2D c(point2,rad); rc.fin_pos.loc=AvoidtoEnterCircle(c,wm->ourRobot[id].pos.loc,rc.fin_pos.loc); qDebug()<< "In Margins Pos : ball = ( " << point2.x << ","<< point2.y << ")"; qDebug()<< "In Margins Pos : delta = ( " << dlta.x << ","<< dlta.y << ")"; qDebug()<< "In Margins Pos : fin_pos = ( " << rc.fin_pos.loc.x << ","<<rc.fin_pos.loc.y << ")"; qDebug()<< "In Margins Pos : Robot = ( " << wm->ourRobot[id].pos.loc.x << ","<<wm->ourRobot[id].pos.loc.y << ")"; rc.fin_pos.dir=dlta.dir().radian()-side*M_PI/2; reach=wm->kn->ReachedToPos(wm->ourRobot[id].pos,rc.fin_pos,20,7); // wm->ourRobot[id].pos.loc,rc.fin_pos.loc,200); qDebug() << "dist To final Pos : " << (wm->ourRobot[id].pos.loc-rc.fin_pos.loc).length(); qDebug() << " Avoided : " << Avoided << " reach" << reach; if(reach) statemargin = 1; } break; case 1:{ rc.fin_pos.dir = dlta.dir().radian() - side*0.9*M_PI ; rc.fin_pos.loc=point2-dlta; qDebug() << "Fin_POS . dir = " << AngleDeg::rad2deg(rc.fin_pos.dir) << " ROBOT . dir = " << AngleDeg::rad2deg(wm->ourRobot[id].pos.dir); if(((wm->ourRobot[id].pos.loc-point2).length())>300) statemargin=0; double delta_ang=wm->ourRobot[id].pos.dir-rc.fin_pos.dir; if (delta_ang > M_PI) delta_ang -= (M_PI * 2); if (delta_ang < -M_PI) delta_ang += (M_PI * 2); if(fabs(delta_ang) < AngleDeg::deg2rad(10)) statemargin=0; rc.maxSpeed=1.7; // bool chighz=wm->kn->ReachedToPos(wm->ourRobot[id].pos,rc.fin_pos,20,10); // if(chighz) statemargin=0; // if((wm->ourRobot[id].pos.loc.dir()-rc.fin_pos.dir)<AngleDeg::deg2rad(10)) statemargin=0; // if(((wm->ourRobot[id].pos.loc-rc.fin_pos.loc).length())<250) state=0; } break; } } } // if(DontEnterCircle && circularBorderDANGER.contains(wm->ourRobot[id].pos.loc) && circularBorder2.contains(point2))//circularBorderDANGER.contains(rc.fin_pos.loc)) // { // rc.fin_pos.loc=circularBorderDANGER.nearestpoint(point2);//wm->ourRobot[id].pos.loc;//AvoidtoEnterCircle(circularBorderDANGER,point2); // rc.maxSpeed=1.1; // } // qDebug()<< "BEFOR ANY CHANGE " << "fin_pos.x " << rc.fin_pos.loc.x << " Y "<<rc.fin_pos.loc.y<< " ------------------------------ STATE = " << state << " STATE 2 =" << state2; // qDebug()<< " " << "ROBOT POS.x " << wm->ourRobot[id].pos.loc.x << " Y "<< wm->ourRobot[id].pos.loc.y; // qDebug() << "Distance To Fin_Pos = " << (rc.fin_pos.loc-wm->ourRobot[id].pos.loc).length(); rc.fin_pos.loc=KeepInField(rc); if(/*((wm->ourRobot[id].pos.loc-opp).length() < 700)*/!OppIsKhoraak && oppIsValid ) { rc.fin_pos.loc=AvoidtoEnterCircle(circularBorderDANGER,wm->ourRobot[id].pos.loc,rc.fin_pos.loc);//rc.fin_pos.loc); } rc.fin_pos.loc=AvoidtoEnterCircle(hole1_Offset,wm->ourRobot[id].pos.loc,rc.fin_pos.loc); rc.fin_pos.loc=AvoidtoEnterCircle(hole2_Offset,wm->ourRobot[id].pos.loc,rc.fin_pos.loc); if(oppIsValid && OppIsKhoraak) rc.fin_pos.loc=opp; qDebug() << "State Margin = " << statemargin; // if(!OppIsKhoraak) // { // Circle2D c(opp,2*ROBOT_RADIUS+350); // rc.fin_pos.loc=AvoidtoEnterCircle(c,wm->ourRobot[id].pos.loc,rc.fin_pos.loc); // } // bool rich = wm->kn->ReachedToPos(wm->ourRobot[id].pos,rc.fin_pos,10,5); // if(rich) rc.fin_pos.loc=wm->ourRobot[id].pos.loc; // rc.fin_pos.loc=Vector2D(60000,60000); // rc.fin_pos.loc=KeepInField(rc); // rc.fin_pos.loc=Vector2D(MAX_X,MAX_Y); // qDebug() << " DIRECTION ERROR = " << (rc.fin_pos.dir-wm->ourRobot[id].pos.dir)*(180/3.14); //rc.useNav = true; // rc.maxSpeed=1.8*rc.maxSpeed; // rc.isBallObs = false; // rc.isKickObs = false; qDebug()<< "INDEX = " << index << "fin_pos.x " << rc.fin_pos.loc.x << " Y "<<rc.fin_pos.loc.y<< " ------------------------------ STATE = " << state << " STATE 2 =" << state2; //qDebug()<< " " << "ROBOT POS.x " << wm->ourRobot[id].pos.loc.x << " Y "<< wm->ourRobot[id].pos.loc.y; //qDebug() << "Distance To Fin_Pos = " << (rc.fin_pos.loc-wm->ourRobot[id].pos.loc).length(); // qDebug() << " IS INSIDE = " << IsInside << " UN ACCESSIBLE :" << unAccessible; // qDebug() << " BALL SIZE : " << wm->balls.size(); // qDebug() << " ROBOT IS IN CORNER " << IsInCorner(wm->ourRobot[id].pos.loc,70) << " Robot Is In Margin : " << IsInmargins(wm->ourRobot[id].pos.loc,70) ; rc.maxSpeed=1.21*rc.maxSpeed; return rc; }
RobotCommand TacticTransferObject::getCommand() { AllInMargin=true; RobotCommand rc; if(!wm->ourRobot[id].isValid) return rc; rc.useNav=true; rc.maxSpeed = 1; rc.fin_pos.loc=wm->endPoint;//Vector2D(300,0); int object; addData(); mergeData(); sortData(); // if(wm->balls.size() > 0) // { // qDebug()<< " BALLL . X = " << wm->balls.at(0)->pos.loc.x << " BALLL . Y = " << wm->balls.at(0)->pos.loc.y; // qDebug() << " MAX x : " << region[1].maxX() << " MIN X : " << region[1].minX() ; // qDebug() << " MAX y : " << region[1].maxY() << " MIN y : " << region[1].minY() ; // if(region[0].IsInside(wm->balls.at(0)->pos.loc)) qDebug() << " THE BALLLLL ISSS INNNNN SIDE !!!!!!!!!!!!!!!!!!!!!!1"; // } index = -1; for(int i=0;i<mergedList.size();i++) { // qDebug() << i << " AT : (" << mergedList.at(i).pos.x << "," << mergedList.at(i).pos.y << ")"; temp=0; if(!region[mergedList.at(i).goalRegion].IsInside(mergedList.at(i).pos) && !IsInmargins(mergedList.at(i).pos,300)) { //qDebug() <<" OBJECT : " << mergedList.at(i).pos.x << " ------ Y = " << mergedList.at(i).pos.y;// TOOOOOOOOOOOOOOOOOOOSHE !!!!!!!" << index ; // AllInMargin=false; index=i; goalRegion=mergedList.at(i).goalRegion; temp=1; break; } } for(int i=0; i<mergedList.size(); i++) { if(!IsInmargins(mergedList.at(i).pos,300)) { AllInMargin=false; } } if(AllInMargin) { for(int i=0;i<mergedList.size();i++) { if(!region[mergedList.at(i).goalRegion].IsInside(mergedList.at(i).pos)) { index=i; goalRegion=mergedList.at(i).goalRegion; break; } } } // if(index ==-1) // { // for(int i=0;i<wm->Chasbideh.size(); i++) // { // if(!region[0].IsInside(wm->Chasbideh.at(i).position) && !region[1].IsInside(wm->Chasbideh.at(i).position)) // { // //qDebug() <<" OBJECT : " << mergedList.at(i).pos.x << " ------ Y = " << mergedList.at(i).pos.y;// TOOOOOOOOOOOOOOOOOOOSHE !!!!!!!" << index ; // index=i; // goalRegion=0;//mergedList.at(i).goalRegion; // temp=1; // break; // } // } // } // qDebug() << mergedList.size() << " MERGED SIZE " ; if(index != -1) { Vector2D point2 = mergedList.at(index).pos; Vector2D diff2 = region[goalRegion].center() - point2; bool reach=false; if(temp!=0) { switch(state) { case 0:{ //Go Behind the Object Vector2D space2=diff2; space2.setLength(300); rc.maxSpeed=1.4; rc.useNav = true; rc.fin_pos.loc=point2 - space2; rc.fin_pos.dir=diff2.dir().radian(); object=findnearestObject(mergedShapeList,wm->ourRobot[id].pos.loc); if(object!=-1) ObsC=Circle2D(mergedShapeList.at(object).position,(mergedShapeList.at(object).roundedRadios+ROBOT_RADIUS+150)); rc.fin_pos.loc=AvoidtoEnterCircle(ObsC,wm->ourRobot[id].pos.loc,rc.fin_pos.loc); reach=wm->kn->ReachedToPos(wm->ourRobot[id].pos.loc,rc.fin_pos.loc,150); if(reach) state = 1; } break; case 1:{//Ready to Push rc.useNav = false; rc.maxSpeed=1.2; rc.fin_pos.loc.x=point2.x - (100 + ROBOT_RADIUS)*(diff2.x)/(diff2.length()); // 100 >> Rounded Radius rc.fin_pos.loc.y=point2.y - (100 + ROBOT_RADIUS)*(diff2.y)/(diff2.length()); rc.fin_pos.dir=diff2.dir().radian(); if(((wm->ourRobot[id].pos.loc-point2).length())>400) state=0; reach=wm->kn->ReachedToPos(wm->ourRobot[id].pos.loc,rc.fin_pos.loc,100); if(reach) state = 2; } break; case 2:{//Push //Vector2D diff2 = region2.center() - wm->ourRobot[id].pos.loc ; rc.useNav = false; rc.maxSpeed=1; //if(diff2.length() > 1500) diff2.setLength(1500); // if(((wm->ourRobot[id].pos.loc-point2).length())>400) state=0; diff2.setLength(300); if(((wm->ourRobot[id].pos.loc-point2).length())>600) state=0; if(((wm->ourRobot[id].pos.loc-rc.fin_pos.loc).length())<50) state=0; Vector2D o2r = ( point2 - wm->ourRobot[id].pos.loc ); if(fabs(wm->ourRobot[id].pos.dir - o2r.dir().radian()) > AngleDeg::deg2rad(40)) { qDebug() << " !!!! Out OF Direction !!!! " ; state=1;//4; } rc.fin_pos.loc=point2 + diff2;//5; rc.fin_pos.dir=diff2.dir().radian(); reach=wm->kn->ReachedToPos(wm->ourRobot[id].pos.loc,rc.fin_pos.loc,10); if(reach) state = 3; } break; case 3:{//Release if(region[goalRegion].IsInside(point2)) { //qDebug() << " INNNNNNNNNNNN SIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIDE !!!"; //if(index==agentsR1.size()) rc.fin_pos.loc=Vector2D(0,0); if(temp==0) { rc.fin_pos.loc=Vector2D(0,0); break; } //agentsR1.takeFirst(); //index++; } //if(reach) state = 0; } break; case 4:{// back behind the object } break; } } Vector2D dlta; double mrgn=300; if(IsInmargins(point2,mrgn)) { // qDebug() << " IS IN MARGIN !!!!!!!!!"; int side = ((point2.x-mean_x)/abs(point2.x-mean_x))*((point2.y-mean_y)/abs(point2.y-mean_y)); if(point2.x > MAX_X-mrgn || point2.x < MIN_X+mrgn) { side *= ((point2.y-mean_y)/abs(point2.y-mean_y)); dlta=Vector2D(side*10,side*(ROBOT_RADIUS+/*mergedShapeList.at(index).roundedRadios+*/50));} else if(point2.y > MAX_Y-mrgn || point2.y < MIN_Y+mrgn) { side *=((point2.x-mean_x)/abs(point2.x-mean_x)); dlta=Vector2D(side*(ROBOT_RADIUS+/*mergedShapeList.at(index).roundedRadios+*/50),side*10);} switch(statemargin) { case 0:{ rc.fin_pos.loc=point2+dlta; // object=findnearestObject(mergedShapeList,wm->ourRobot[id].pos.loc); // if(object!=-1) ObsC=Circle2D(mergedShapeList.at(object).position,(mergedShapeList.at(object).roundedRadios+ROBOT_RADIUS)); // rc.fin_pos.loc=AvoidtoEnterCircle(ObsC,wm->ourRobot[id].pos.loc,rc.fin_pos.loc); // int rad = mergedShapeList.at(index).roundedRadios+ROBOT_RADIUS; // Circle2D c(point2,rad); // rc.fin_pos.loc=AvoidtoEnterCircle(c,wm->ourRobot[id].pos.loc,rc.fin_pos.loc); // qDebug()<< "In Margins Pos : ball = ( " << point2.x << ","<< point2.y << ")"; // qDebug()<< "In Margins Pos : delta = ( " << dlta.x << ","<< dlta.y << ")"; // qDebug()<< "In Margins Pos : fin_pos = ( " << rc.fin_pos.loc.x << ","<<rc.fin_pos.loc.y << ")"; // qDebug()<< "In Margins Pos : Robot = ( " << wm->ourRobot[id].pos.loc.x << ","<<wm->ourRobot[id].pos.loc.y << ")"; rc.fin_pos.dir=dlta.dir().radian()-side*M_PI/2; reach=wm->kn->ReachedToPos(wm->ourRobot[id].pos,rc.fin_pos,20,7); // wm->ourRobot[id].pos.loc,rc.fin_pos.loc,200); // qDebug() << "dist To final Pos : " << (wm->ourRobot[id].pos.loc-rc.fin_pos.loc).length(); // qDebug() << " Avoided : " << Avoided << " reach" << reach; if(reach) statemargin = 1; } break; case 1:{ rc.fin_pos.dir = dlta.dir().radian() - side*0.9*M_PI ; rc.fin_pos.loc=point2-dlta; // qDebug() << "Fin_POS . dir = " << AngleDeg::rad2deg(rc.fin_pos.dir) << " ROBOT . dir = " << AngleDeg::rad2deg(wm->ourRobot[id].pos.dir); if(((wm->ourRobot[id].pos.loc-point2).length())>300) statemargin=0; double delta_ang=wm->ourRobot[id].pos.dir-rc.fin_pos.dir; if (delta_ang > M_PI) delta_ang -= (M_PI * 2); if (delta_ang < -M_PI) delta_ang += (M_PI * 2); if(fabs(delta_ang) < AngleDeg::deg2rad(10)) statemargin=0; rc.maxSpeed=1.7; // bool chighz=wm->kn->ReachedToPos(wm->ourRobot[id].pos,rc.fin_pos,20,10); // if(chighz) statemargin=0; // if((wm->ourRobot[id].pos.loc.dir()-rc.fin_pos.dir)<AngleDeg::deg2rad(10)) statemargin=0; // if(((wm->ourRobot[id].pos.loc-rc.fin_pos.loc).length())<250) state=0; } break; } } // qDebug() << rc.fin_pos.loc.x << " ------- Y = " << rc.fin_pos.loc.y << " STATE = " << state; // qDebug() << "STATE = " << state; } //rc.maxSpeed = 1.2;//rc.maxSpeed; // rc.fin_pos.loc.x=rcpast.x + 0.1*(rc.fin_pos.loc.x-rcpast.x); // rc.fin_pos.loc.y=rcpast.y + 0.1*(rc.fin_pos.loc.y-rcpast.y); // rcpast=rc.fin_pos.loc; // qDebug() << " INDEX = " << index ; rc.maxSpeed/=1.4; if(IsInmargins(wm->ourRobot[id].pos.loc,500)) rc.maxSpeed /= 1.5 ; rc.fin_pos.loc=KeepInField(rc); // qDebug() << " This Object Is For Region " << goalRegion ; rc.useNav=false; rc.isBallObs = false; rc.isKickObs = true; return rc; }
/*What will happen when pressed ENTER while standing on chosen area*/ void pMAction(int aChar) { if (strcmp(mapName, "menu") == 0) { switch (aChar) { case 1: break; case 0: useDoor(E, UP); useDoor(F, DOWN); useDoor(H, LEFT); useDoor(G, RIGHT); break; } } else if (strcmp(mapName, "sorting") == 0) { switch (aChar) { case 1: sortData(1, v_order); break; case 2: sortData(2, v_order); break; case 3: sortData(3, v_order); break; case 4: sortData(4, v_order); break; case 5: sortData(5, v_order); break; case O: initializeData(); break; case U: v_order = UP; break; case D: v_order = DOWN; break; /*@*/ case (64-48): switchMap("menu"); break; } } else if (strcmp(mapName, "filtering") == 0) { switch (aChar) { case O: loadGlobalActions(mapName); activateDatabase(movies_database); initializeData(); cMAppearance(U, 0, 0, ' '); cMAppearance(I, 0, 0, ' '); break; case Z: if (action1 == 1 && action2 == FALSE) break; if (action1 != FALSE) { passValue(column1, &action2); teleport (U); openDoor(Q, DOWN); if (action2 != FALSE) cMAppearance(U, 0, 0, '*'); } else { passValue(column1, &action1); teleport (I); openDoor(W, UP); if (action1 != FALSE) cMAppearance(I, 0, 0, '*'); } break; case X: if (action1 == 2 && action2 == FALSE) break; if (action1 != FALSE) { passValue(column2, &action2); teleport (U); openDoor(Q, DOWN); if (action2 != FALSE) cMAppearance(U, 0, 0, '*'); } else { passValue(column2, &action1); teleport (I); openDoor(W, UP); if (action1 != FALSE) cMAppearance(I, 0, 0, '*'); } break; case C: if (action1 == 3 && action2 == FALSE) break; if (action1 != FALSE) { passValue(column3, &action2); teleport (U); openDoor(Q, DOWN); if (action2 != FALSE) cMAppearance(U, 0, 0, '*'); } else { passValue(column3, &action1); teleport (I); openDoor(W, UP); if (action1 != FALSE) cMAppearance(I, 0, 0, '*'); } break; case V: if (action1 == 4 && action2 == FALSE) break; if (action1 == TRUE) { passValue(column4, &action2); teleport (U); openDoor(Q, DOWN); if (action2 != FALSE) cMAppearance(U, 0, 0, '*'); } else { passValue(column4, &action1); teleport (I); openDoor(W, UP); if (action1 != FALSE) cMAppearance(I, 0, 0, '*'); } break; case B: if (action1 == 5 && action2 == FALSE) break; if (action1 != FALSE) { passValue(column5, &action2); teleport (U); openDoor(Q, DOWN); if (action2 != FALSE) cMAppearance(U, 0, 0, '*'); } else { passValue(column5, &action1); teleport (I); openDoor(W, UP); if (action1 != FALSE) cMAppearance(I, 0, 0, '*'); } break; case 6: useDoor(E, RIGHT); break; case 9: switch (action1) { case 1: switch (action2) { case 2: filterData(action1, v_column1, action2, v_column2); break; case 3: filterData(action1, v_column1, action2, v_column3); break; case 4: filterData(action1, v_column1, action2, v_column4); break; case 5: filterData(action1, v_column1, action2, v_column5); break; } break; case 2: switch (action2) { case 1: filterData(action1, v_column2, action2, v_column1); break; case 3: filterData(action1, v_column2, action2, v_column3); break; case 4: filterData(action1, v_column2, action2, v_column4); break; case 5: filterData(action1, v_column2, action2, v_column5); break; } break; case 3: switch (action2) { case 1: filterData(action1, v_column3, action2, v_column1); break; case 2: filterData(action1, v_column3, action2, v_column2); break; case 4: filterData(action1, v_column3, action2, v_column4); break; case 5: filterData(action1, v_column3, action2, v_column5); break; } break; case 4: switch (action2) { case 1: filterData(action1, v_column4, action2, v_column1); break; case 2: filterData(action1, v_column4, action2, v_column2); break; case 3: filterData(action1, v_column4, action2, v_column3); break; case 5: filterData(action1, v_column4, action2, v_column5); break; } break; case 5: switch (action2) { case 1: filterData(action1, v_column5, action2, v_column1); break; case 2: filterData(action1, v_column5, action2, v_column2); break; case 3: filterData(action1, v_column5, action2, v_column3); break; case 4: filterData(action1, v_column5, action2, v_column4); break; } break; } break; /*@*/ case (64-48): switchMap("menu"); break; } } else { perror ("'mapName' out of speck"); SC(mapName); assert(!TRUE); } mapConditions(); }
bool SM_ModelBackend::loadFromDomDoc (QDomDocument &doc) { QMessageBox msgBox; // let us check if we have a valid subnetmap QDomElement docElem = doc.documentElement(); if (docElem.nodeName()=="SubnetMap") { if (docElem.hasAttribute("fileformat")) { if ((docElem.attribute("fileformat")).toInt()!=2) { msgBox.setText("Warning: the SubnetMap you were trying to load has the wrong format. This Version of SubnetMapper can only read format version 2."); msgBox.setIcon(QMessageBox::Warning); msgBox.setDetailedText("The fileformat attribute of the SubnetMap node has a version number that is not equal to 2. Update SubnetMapper to the most recent version to read this file."); msgBox.exec(); return false; }; } } else return false; // now we know its one of ours. // we can clear all data now, but we do emit only the message to notify // everyone about the emptied model. The change-signals wil be emitted // at the end of this function. This makes sure that no widget will work // without a valid reason at this point. clearData(true); emit modelEmptied(); QDomNodeList subnetNodes = docElem.elementsByTagName("subnet"); // qDebug("SM_DataModel::loadFromDomDoc(): found %u subnet nodes in the document.",subnetNodes.count()); for (int i=0;i<subnetNodes.count();i++){ QDomElement currentSubnetNode=subnetNodes.at(i).toElement(); QDomElement addressNode = currentSubnetNode.firstChildElement("address"); QDomElement netmaskNode = currentSubnetNode.firstChildElement("netmask"); QDomElement colorNode = currentSubnetNode.firstChildElement("color"); QDomElement descriptionNode = currentSubnetNode.firstChildElement("description"); QDomElement notesNode = currentSubnetNode.firstChildElement("notes"); QDomElement identifierNode = currentSubnetNode.firstChildElement("identifier"); if (currentSubnetNode.hasAttribute("ipversion")) { if (currentSubnetNode.attribute("ipversion")=="IPv4") { Subnet_v4 *newSubnet = new Subnet_v4(this); QString mom=netmaskNode.text(); newSubnet->setNM(mom); mom=addressNode.text(); newSubnet->setIP(mom); mom=identifierNode.text(); newSubnet->setIdentifier(mom); mom=descriptionNode.text(); newSubnet->setDescription(mom); mom=notesNode.text(); newSubnet->setNotes(mom); QColor momColor= QColor(colorNode.text()); newSubnet->setColor(momColor); SubnetList.append(newSubnet); Subnet4List.append(newSubnet); } else if (currentSubnetNode.attribute("ipversion")=="IPv6") { Subnet_v6 *newSubnet = new Subnet_v6(this); QString mom=netmaskNode.text(); //qDebug("SM_ModelBackend::loadFromDomDoc(): parsed IPv6 Netmask: %s",qPrintable(mom.toUtf8())); newSubnet->setNM(mom); mom=addressNode.text(); //qDebug("SM_ModelBackend::loadFromDomDoc(): parsed IPv6 IP: %s",qPrintable(mom.toUtf8())); newSubnet->setIP(mom); mom=identifierNode.text(); newSubnet->setIdentifier(mom); mom=descriptionNode.text(); newSubnet->setDescription(mom); mom=notesNode.text(); newSubnet->setNotes(mom); QColor momColor= QColor(colorNode.text()); newSubnet->setColor(momColor); SubnetList.append(newSubnet); Subnet6List.append(newSubnet); } else { msgBox.setText("Warning: Subnet "+QString::number(i)+" was invalid! Subnet will be skipped..."); msgBox.setIcon(QMessageBox::Warning); msgBox.setDetailedText("The Subnet was not clearly specified, the ipversion attribute is invalid."+ identifierNode.text()+"\n"+ addressNode.text()+"\n"+ netmaskNode.text()+"\n"+ descriptionNode.text()+"\n"+ notesNode.text()+"\n"+ colorNode.text()+"\n" ); msgBox.exec(); } } else { msgBox.setText("Warning: Subnet "+QString::number(i)+" was invalid! Subnet will be skipped..."); msgBox.setIcon(QMessageBox::Warning); msgBox.setDetailedText("The Subnet was not clearly specified, the ipversion attribute is missing."+ identifierNode.text()+"\n"+ addressNode.text()+"\n"+ netmaskNode.text()+"\n"+ descriptionNode.text()+"\n"+ notesNode.text()+"\n"+ colorNode.text()+"\n" ); msgBox.exec(); } } sortData(); emit data4Changed(); emit data6Changed(); emit dataChanged(); // uncomment for debugging purposes, prints all objects in model dumpAllSubnets(); return true; }
int main(int argc, char *argv[]) { int processId, numberOfProcesses, chunkSize, numberOfElements;; int *chunk = NULL; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &processId); MPI_Comm_size(MPI_COMM_WORLD, &numberOfProcesses); /********************************************* MASTER PART 1 *********************************************/ if (processId==MASTER) { if (argc!=2) { printf("Error in number of parameters\n"); MPI_Abort(MPI_COMM_WORLD, 0); return 0; } fillInputFile(argv[1]); FILE *inputFilePtr = fopen(argv[1], "rb"); if (inputFilePtr==NULL) { printf("Error while opening the input file\n"); MPI_Abort(MPI_COMM_WORLD, 0); return 0; } fread(&numberOfElements, 1, sizeof(int), inputFilePtr); MPI_Bcast(&numberOfElements, 1, MPI_INT, MASTER, MPI_COMM_WORLD); int elementsPerProcess = numberOfElements / (numberOfProcesses-1); int rest = numberOfElements % (numberOfProcesses-1); for (int i = 1; i < numberOfProcesses; ++i) { chunkSize = elementsPerProcess; chunkSize += (i <= rest) ? 1 : 0; chunk = realloc(chunk, chunkSize * sizeof(int)); fread(chunk, chunkSize, sizeof(int), inputFilePtr); MPI_Send(&chunkSize, 1, MPI_INT, i, 0, MPI_COMM_WORLD); MPI_Send(chunk, chunkSize, MPI_INT, i, 1, MPI_COMM_WORLD); } fclose(inputFilePtr); /********************************************* MASTER PART 2 *********************************************/ int *receivedMins = malloc(numberOfProcesses * sizeof(int)); int minVal, minIndex; for (int globalIterator = 0; globalIterator < numberOfElements; ++globalIterator) { minVal=MAX_INT; minIndex=0; MPI_Gather(&MAX_INT, 1, MPI_INT, receivedMins, 1, MPI_INT, MASTER, MPI_COMM_WORLD); for (int i = 0; i < numberOfProcesses; ++i) { if (receivedMins[i]<minVal) { minVal = receivedMins[i]; minIndex = i; } } printf("Num %d = %d\n", globalIterator+1, minVal); MPI_Bcast(&minIndex, 1, MPI_INT, MASTER, MPI_COMM_WORLD); } free(receivedMins); } /********************************************* SLAVES PART 1 *********************************************/ else { MPI_Bcast(&numberOfElements, 1, MPI_INT, MASTER, MPI_COMM_WORLD); MPI_Recv(&chunkSize, 1, MPI_INT, MASTER, 0, MPI_COMM_WORLD, NULL); chunk = realloc(chunk, chunkSize * sizeof(int)); MPI_Recv(chunk, chunkSize, MPI_INT, MASTER, 1, MPI_COMM_WORLD, NULL); sortData(chunk, chunkSize); /********************************************* SLAVES PART 2 *********************************************/ int position = 0, winner; for (int globalIterator = 0; globalIterator < numberOfElements; ++globalIterator) { if (position < chunkSize) { MPI_Gather(&chunk[position], 1, MPI_INT, NULL, 1, MPI_INT, MASTER, MPI_COMM_WORLD); } else { MPI_Gather(&MAX_INT, 1, MPI_INT, NULL, 1, MPI_INT, MASTER, MPI_COMM_WORLD); } MPI_Bcast(&winner, 1, MPI_INT, MASTER, MPI_COMM_WORLD); position += (winner == processId) ? 1 : 0; } } free(chunk); MPI_Finalize(); return 0; }
void Repository::removeTask(const Task& t){ task.erase(remove(task.begin(), task.end(), t), task.end()); sortData(); notify(); }