int main() { clock_t start, end; struct timeval t1, t2; double timecost; // start timer gettimeofday(&t1, NULL); int i; Allocate_Memory(); Init(); for(i = 0;i < no_steps;i++) { CalculateFlux(); CalculateFPFM(); CalculateResult(); } Save_Results(); Free(); // stop timer gettimeofday(&t2, NULL); // compute and print time cost in ms timecost = (t2.tv_sec - t1.tv_sec) * 1000.0; // sec to ms timecost += (t2.tv_usec - t1.tv_usec) / 1000.0; // us to ms printf("Code time cost: %f\n", timecost); return 0; }
bool AbstractContest::SaveSolution() { ContestResult result = CalculateResult(); const bool improved = result.score > best_result.score; if (!improved) return false; best_result = result; CopySolution(best_solution); return true; }
void Keys(unsigned char key, int x, int y) { if (stat.turnedON) { switch (key) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': ReadCharacter(key); break; case '.': if (stat.decimalOperation == 0) { if (stat.currentOperand == 0) { stat.operandLength++; if (stat.operandLength > 10) { return; } operand1Str[opr1Index++] = '.'; stat.decimalOperation = 1; } else if (stat.currentOperand == 1) { stat.operandLength++; if (stat.operandLength > 10) { return; } operand2Str[opr2Index++] = '.'; stat.decimalOperation = 1; } totalExp[expIndex++] = '.'; } else if (stat.decimalOperation == 1) return; break; case '+': ReadOperator('+'); break; case '-': ReadOperator('-'); break; case '*': ReadOperator('*'); break; case '/': ReadOperator('/'); break; case '=': case 13: //ASCII value of return key CalculateResult(); break; case 27: //ASCII value of Escape key ClearEverything(); break; default: printf("Invalid Character Chosen\n"); return; break; } glutPostRedisplay(); } else return; }
void Mouse(int btn, int state, int x, int y) { if (stat.turnedON) { if (btn == GLUT_LEFT_BUTTON && (x > 15 && x<70) && (y>455 && y<505) && state == GLUT_DOWN) { ReadCharacter('0'); glutPostRedisplay(); } else if (btn == GLUT_LEFT_BUTTON && (x>90 && x<145) && (y>455 && y<505) && state == GLUT_DOWN) { if (stat.decimalOperation == 0) { if (stat.currentOperand == 0) { stat.operandLength++; if (stat.operandLength > 10) { return; } operand1Str[opr1Index++] = '.'; stat.decimalOperation = 1; } else if (stat.currentOperand == 1) { stat.operandLength++; if (stat.operandLength > 10) { return; } operand2Str[opr2Index++] = '.'; stat.decimalOperation = 1; } totalExp[expIndex++] = '.'; } else if (stat.decimalOperation == 1) return; glutPostRedisplay(); } else if (btn == GLUT_LEFT_BUTTON && (x > 15 && x<70) && (y>380 && y<430) && state == GLUT_DOWN) { ReadCharacter('1'); glutPostRedisplay(); } else if (btn == GLUT_LEFT_BUTTON && (x>90 && x<145) && (y>380 && y<430) && state == GLUT_DOWN) { ReadCharacter('2'); glutPostRedisplay(); } else if (btn == GLUT_LEFT_BUTTON && (x>165 && x<220) && (y>380 && y<430) && state == GLUT_DOWN) { ReadCharacter('3'); glutPostRedisplay(); } else if (btn == GLUT_LEFT_BUTTON && (x>15 && x<70) && (y>305 && y<355) && state == GLUT_DOWN) { ReadCharacter('4'); glutPostRedisplay(); } else if (btn == GLUT_LEFT_BUTTON && (x>90 && x<145) && (y>305 && y<355) && state == GLUT_DOWN) { ReadCharacter('5'); glutPostRedisplay(); } else if (btn == GLUT_LEFT_BUTTON && (x>165 && x<220) && (y>305 && y<355) && state == GLUT_DOWN) { ReadCharacter('6'); glutPostRedisplay(); } else if (btn == GLUT_LEFT_BUTTON && (x>15 && x<70) && (y>230 && y<280) && state == GLUT_DOWN) { ReadCharacter('7'); glutPostRedisplay(); } else if (btn == GLUT_LEFT_BUTTON && (x>90 && x<145) && (y>230 && y<280) && state == GLUT_DOWN) { ReadCharacter('8'); glutPostRedisplay(); } else if (btn == GLUT_LEFT_BUTTON && (x>165 && x<220) && (y>230 && y<280) && state == GLUT_DOWN) { ReadCharacter('9'); glutPostRedisplay(); } else if (btn == GLUT_LEFT_BUTTON && (x>240 && x<295) && (y>455 && y<505) && state == GLUT_DOWN) { ReadOperator('+'); glutPostRedisplay(); } else if (btn == GLUT_LEFT_BUTTON && (x>240 && x<295) && (y>380 && y<430) && state == GLUT_DOWN) { ReadOperator('-'); glutPostRedisplay(); } else if (btn == GLUT_LEFT_BUTTON && (x>240 && x<295) && (y>305 && y<355) && state == GLUT_DOWN) { ReadOperator('*'); glutPostRedisplay(); } else if (btn == GLUT_LEFT_BUTTON && (x>240 && x<295) && (y>230 && y<280) && state == GLUT_DOWN) { ReadOperator('/'); glutPostRedisplay(); } else if (btn == GLUT_LEFT_BUTTON && (x > 165 && x<295) && (y>155 && y<205) && state == GLUT_DOWN) { //AC is clicked ClearEverything(); glutPostRedisplay(); } else if (btn == GLUT_LEFT_BUTTON && (x>165 && x<220) && (y>455 && y < 505) && state == GLUT_DOWN) { // = is clicked CalculateResult(); glutPostRedisplay(); } else if (btn == GLUT_LEFT_BUTTON && (x>90 && x<145) && (y>155 && y<205) && state == GLUT_DOWN) { exit(0); } } else if (btn == GLUT_LEFT_BUTTON && (x>15 && x<70) && (y>155 && y<205) && state == GLUT_DOWN) { stat.turnedON = 1; glutPostRedisplay(); } }
ContestResult ContestDijkstra::CalculateResult() const { return CalculateResult(solution); }