void TaskPacker::findDateAndTime(int index) { _chronoInterpreter->interpretDateAndTime(_tokens, index); findTime(index); findDate(index); return; }
ViewElementList::iterator ViewElementList::findNearestTime(timeT t) { iterator i = findTime(t); if (i == end() || (*i)->getViewAbsoluteTime() > t) { if (i == begin()) return end(); else --i; } return i; }
// {{{ 早さ最適化経路 void bfsFast(void) { int i; end = 0; top = 0; int *dp; dp = malloc((n + 1) * sizeof(int)); for (i = 0; i < n; i++) dp[i] = INF; push(startStation, startTime, 0); while(top != end) { int s = topS(); int t = topT(); int c = topC(); pop(); for (i = 0; i < nextTransLast[s]; i++) { int currentS = nextTrans[s][i]; int currentC = c; int currentT = t; if (s != currentS) currentC++; if (dp[currentS] > currentT) { dp[currentS] = currentT; way_copy(currentS, s); way_pb(currentS, currentS, currentT); if (currentS != goal) push(currentS, currentT, currentC); } int reachS = nextGo[currentS]; if (reachS == - 1) continue; int reachC = currentC; int reachT = findTime(currentS, currentT); //timeArriveをかえす if (dp[reachS] > reachT) { dp[reachS] = reachT; way_copy(reachS, s); way_pb(reachS, currentS, currentT); way_pb(reachS, reachS, reachT); push(reachS, reachT, reachC); } } } }
double delayImpl(DATA* data, int exprNumber, double exprValue, double time, double delayTime, double delayMax) { RINGBUFFER* delayStruct = data->simulationInfo.delayStructure[exprNumber]; int length = ringBufferLength(delayStruct); DEBUG_INFO4(LOG_EVENTS, "delayImpl: exprNumber = %d, exprValue = %g, time = %g, delayTime = %g", exprNumber, exprValue, time, delayTime); /* Check for errors */ ASSERT1(0 <= exprNumber, "invalid exprNumber = %d", exprNumber); ASSERT1(exprNumber < data->modelData.nDelayExpressions, "invalid exprNumber = %d", exprNumber); if(time <= data->simulationInfo.tStart) { DEBUG_INFO1(LOG_EVENTS, "delayImpl: Entered at time < starting time: %g.", exprValue); return (exprValue); } if(delayTime < 0.0) { ASSERT1(0.0 < delayTime, "Negative delay requested: delayTime = %g", delayTime); THROW("Negative delay requested"); } if(length == 0) { /* This occurs in the initialization phase */ DEBUG_INFO1(LOG_EVENTS, "delayImpl: Missing initial value, using argument value %g instead.", exprValue); return (exprValue); } /* * Returns: expr(time?delayTime) for time>time.start + delayTime and * expr(time.start) for time <= time.start + delayTime. * The arguments, i.e., expr, delayTime and delayMax, need to be subtypes of Real. * DelayMax needs to be additionally a parameter expression. * The following relation shall hold: 0 <= delayTime <= delayMax, * otherwise an error occurs. If delayMax is not supplied in the argument list, * delayTime need to be a parameter expression. See also Section 3.7.2.1. * For non-scalar arguments the function is vectorized according to Section 10.6.12. */ if(time <= data->simulationInfo.tStart + delayTime) { double res = ((TIME_AND_VALUE*)getRingData(delayStruct, 0))->value; DEBUG_INFO2(LOG_EVENTS, "findTime: time <= tStart + delayTime: [%d] = %g",exprNumber, res); return res; } else { /* return expr(time-delayTime) */ double timeStamp = time - delayTime; double time0, time1, value0, value1; int i; ASSERT1(0.0 <= delayTime, "Negative delay requested: delayTime = %g", delayTime); /* find the row for the lower limit */ if(timeStamp > ((TIME_AND_VALUE*)getRingData(delayStruct, length - 1))->time) { /* delay between the last accepted time step and the current time */ time0 = ((TIME_AND_VALUE*)getRingData(delayStruct, length - 1))->time; value0 = ((TIME_AND_VALUE*)getRingData(delayStruct, length - 1))->value; time1 = time; value1 = exprValue; } else { i = findTime(timeStamp, delayStruct); ASSERT2(i < length, "%d = i < length = %d", i, length); time0 = ((TIME_AND_VALUE*)getRingData(delayStruct, i))->time; value0 = ((TIME_AND_VALUE*)getRingData(delayStruct, i))->value; /* was it the last value? */ if(i+1 == length) { if(0 < i && delayMax == delayTime) dequeueNFirstRingDatas(delayStruct, i-1); DEBUG_INFO3(LOG_EVENTS, "delayImpl: dequeueNFirstRingDatas[%d] %g = %g", i, delayMax, delayTime); return value0; } time1 = ((TIME_AND_VALUE*)getRingData(delayStruct, i+1))->time; value1 = ((TIME_AND_VALUE*)getRingData(delayStruct, i+1))->value; if(0 < i && delayMax == delayTime) dequeueNFirstRingDatas(delayStruct, i-1); } /* was it an exact match?*/ if(time0 == timeStamp){ DEBUG_INFO2(LOG_EVENTS, "delayImpl: Exact match at %g = %g", timeStamp, value0); return value0; } else if(time1 == timeStamp) { DEBUG_INFO2(LOG_EVENTS, "delayImpl: Exact match at %g = %g", timeStamp, value1); return value1; } else { /* linear interpolation */ double timedif = time1 - time0; double dt0 = time1 - timeStamp; double dt1 = timeStamp - time0; double retVal = (value0 * dt0 + value1 * dt1) / timedif; DEBUG_INFO3(LOG_EVENTS, "delayImpl: Linear interpolation of %g between %g and %g", timeStamp, time0, time1); DEBUG_INFO4(LOG_EVENTS, "delayImpl: Linear interpolation of %g value: %g and %g = %g", timeStamp, value0, value1, retVal); return retVal; } } }
bool LogicDetailParser::parser(Task& task, string text, string operation){ int dateCheck; int timeCheck; string tempDate; string lowercaseText = textChangeLowercase(text); _hoursFlag = false; _taskDescription = text; _time = CANNOTFIND; _date = CANNOTFIND; getIndicators(lowercaseText); if(_slashPosition == NOTSTATED && _hrsPosition == NOTSTATED && _dotPosition == NOTSTATED && _colonPosition == NOTSTATED && _amPosition == NOTSTATED && _pmPosition == NOTSTATED){ task.setTaskDescription(text); return true; } if(_slashPosition != NOTSTATED){ dateCheck = findDate(task, lowercaseText); if(dateCheck == ERROR) return false; else if(dateCheck == FOUND){ tempDate = _date; _taskDescription = trimFoundText(_taskDescription, _date); lowercaseText = textChangeLowercase(_taskDescription); getIndicators(lowercaseText); dateCheck = findDate(task, lowercaseText); if(dateCheck == ERROR) return false; else if(dateCheck == FOUND) _taskDescription = trimFoundText(_taskDescription, _date); else if(dateCheck == NOTFOUND) setTaskDate(task, task.getStartDay(), task.getStartMonth(), task.getStartYear()); } } _date = tempDate; if(!findTime(task, textChangeLowercase(text))) return false; removeUnwantedText(); if(_taskDescription.size() != POINTZERO) task.setTaskDescription(_taskDescription); if(operation == "change"){ if(task.getStartDay() == task.getEndDay() && _hoursFlag) task.setEndDay(task.getStartDay() + POINTONE); return true; } if(operation == "add"){ if(task.getStartDay() == task.getEndDay() && _hoursFlag) task.setEndDay(task.getStartDay() + POINTONE); if (_time != CANNOTFIND && _date != CANNOTFIND){} else if (_time == CANNOTFIND){ task.setStartTime(900); task.setEndTime(1800); } else if (_date == CANNOTFIND) setDate(task); else //floating return false; } }
int manageThreadsAPP(int sock, int argc, char *argv[]) { pthread_t handleReadDURIP_v; pthread_t threadOBSERVETCP; pthread_t threadOBSERVEMAC; pthread_t handleCommDURIP_v; int n; char buffer[256]; char s[8]; bzero(buffer, 256); char ifname[6]; char * test; int second; struct sockaddr_in ip4addr; struct sockaddr_in ip4addrMASK; paramThread_Comm param_comm; paramThread param; paramThread_MACREAD paramMacObser; paramThread_tcp paramThreadTCP; inet_pton(AF_INET, argv[6], &ip4addr.sin_addr); inet_pton(AF_INET, argv[7], &ip4addrMASK.sin_addr); paramThreadTCP.ipNL.subnet = ip4addr.sin_addr.s_addr; paramThreadTCP.ipNL.netmask = ip4addrMASK.sin_addr.s_addr; paramThreadTCP.nameExperiment = (char *)malloc(sizeof(char) *(strlen(argv[5])+1)); strcpy(paramThreadTCP.nameExperiment , argv[5]); n = read(sock, buffer, 255); if (n < 0) { error("ERROR reading from socket"); return -1; } // printf("Value n: %d \n", n); test = malloc((sizeof (char)+1) * n); memcpy(test, buffer, n); printf("Message received: %s \n", buffer); second = atoi(test); free(test); findTime(s); n = write(sock, s, 8); if (n < 0) { error("ERROR writing to socket"); return -1; } paramMacObser.argc = argc; paramMacObser.argv = argv; ctrlPrintGlobal =atoi(argv[1]); ctrlTSGlobal =atoi(argv[2]); printf("SERVER:%s ---- %d\n", argv[4] , (int)strlen(argv[4])); //PARAMETRIZZARE QUESTO VALORE n = write(sock, "START", strlen("START")); strcpy(ifname, argv[4]); strcpy(param.port, argv[0]); strcpy(param.ifname, ifname); if (pthread_mutex_init(&lock, NULL) != 0) { printf("\n mutex init failed\n"); #ifdef __ANDROID__ __android_log_print(ANDROID_LOG_DEBUG, "SERVERREADDURIP", "mutex init failed"); #endif return -1; } if (pthread_mutex_init(&lock_comm, NULL) != 0) { printf("\n mutex init failed\n"); #ifdef __ANDROID__ __android_log_print(ANDROID_LOG_DEBUG, "MACOBSERVATION", "mutex init failed"); #endif return -1; } strcpy(param_comm.port, argv[0]); strcpy(param_comm.ifname, ifname); if (pthread_create(&handleReadDURIP_v, NULL, handleReadDURIP, ¶m) != 0) { #ifdef __ANDROID__ __android_log_print(ANDROID_LOG_DEBUG, "SERVERREADDURIP", "ERROR HANDLE MAC READ DURIP"); #endif printf("Error to create thread\n"); return -2; } //SECTION FOR COMMUNICATIN BETWEEN APP AND MACOBSERVATION if (pthread_create(&handleCommDURIP_v, NULL, handleCommDURIP, ¶m_comm) != 0){ #ifdef __ANDROID__ __android_log_print(ANDROID_LOG_DEBUG, "MACOBSERVATION", "ERROR HANDLE MAC READ DURIP"); #else printf("Error to create thread\n"); #endif return -1; } /* */ sleep(second); /* THREAD OBSERVATION */ if (pthread_create(&threadOBSERVETCP, NULL, tcpObservation, ¶mThreadTCP) != 0) { printf("Error to create thread\n"); return -2; } if (pthread_create(&threadOBSERVEMAC, NULL, macObservation, ¶mMacObser) != 0) { printf("Error to create thread\n"); return -2; } /* CLOSE THREAD */ if (pthread_join(threadOBSERVEMAC , NULL)) { fprintf(stderr, "Error joining thread\n"); return -4; }else{ printf("MAC THREAD DOWN\n"); } // strcpy(folderLocal , folder); // printf("FOLDER LOCAL %s\n" , folderLocal); if (pthread_join(handleReadDURIP_v , NULL)) { fprintf(stderr, "Error joining thread READ\n"); return -4; }else{ printf("HANLDE DURIP DOWN\n"); } shutdown(sockfdCommDurip,SHUT_RDWR); if (pthread_join(handleCommDURIP_v , NULL)) { fprintf(stderr, "Error joining thread HANDLE COMM\n"); return -4; }else{ printf("HANDLE COMM DOWN\n"); } printf("BEFORE TO DROP DOWN TCP THREAD\n"); pthread_kill(threadOBSERVETCP, SIGTERM); // shutdown(sock_fd_rcv,SHUT_RDWR); if (pthread_join(threadOBSERVETCP , NULL)) { fprintf(stderr, "Error joining thread TCP\n"); return -4; }else{ printf("TCP DOWN\n"); } printf("END %s\n" , __FUNCTION__); pthread_mutex_destroy(&lock); pthread_mutex_destroy(&lock_comm); #ifdef __ANDROID__ #else // if (system("cp -r --no-clobber /mnt/local/log/ /home/danielet/Dropbox/COGNET/`uname -n`/")==-1) // error("SYSTEM CALL ERROR"); #endif // printf("CLOSE FORK\n"); // close(sock); return 0; }