void TrollingModel::initialize() { m_DBLayer = new DBLayer(m_filePath+"/database"); connect(m_DBLayer, SIGNAL(storeSignal(int, QString)), &m_journal, SLOT(addJournal(int, QString))); connect(&m_synchronizer, SIGNAL(uploadDone()), this, SLOT(resetJournal())); qDebug() << "start loading"; m_DBLayer->loadObjects(Lure().getType(), &m_factory); m_DBLayer->loadObjects(Trip().getType(), &m_factory); m_DBLayer->loadObjects(Place().getType(), &m_factory); qDebug() << "finished loading"; }
Driver& Driver::loadTripData( const std::vector< std::pair< int, std::vector< std::pair<float,float> > > >& tripData ) { m_trips.clear(); m_trips.reserve( tripData.size() ); for ( std::vector< std::pair< int, std::vector< std::pair<float,float> > > >::const_iterator iTrip = tripData.begin(); iTrip != tripData.end(); ++iTrip ) { m_trips.push_back( Trip( iTrip->first ) ); m_trips.back().setTripData( iTrip->second ); } return *this; }
Trip* TrollingModel::getTrip(int id) { if(id < 0 && getTrollingObject("trip", id) == NULL) { Trip* trip = new Trip(); m_trollingobjects.push_back(trip); return trip; } if(getTrollingObject(Trip().getType(), id) == NULL) qDebug() << "will get NULL trip" << QString::number(id); return reinterpret_cast<Trip*>(getTrollingObject("trip", id)); }
void Simulation::calculateForceGradient(MatrixXd &TVk, SparseMatrix<double>& forceGradient){ forceGradient.setZero(); vector<Trip> triplets1; triplets1.reserve(12*12*M.tets.size()); for(unsigned int i=0; i<M.tets.size(); i++){ //Get P(dxn), dx = [1,0, 0...], then [0,1,0,....], and so on... for all 4 vert's x, y, z //P is the compute Force Differentials blackbox fxn Vector12d dx(12); dx.setZero(); Vector4i indices = M.tets[i].verticesIndex; int kj; for(unsigned int j=0; j<12; j++){ dx(j) = 1; MatrixXd dForces = M.tets[i].computeForceDifferentials(TVk, dx); kj = j%3; //row in order for dfxi/dxi ..dfxi/dzl triplets1.push_back(Trip(3*indices[j/3]+kj, 3*indices[0], dForces(0,0))); triplets1.push_back(Trip(3*indices[j/3]+kj, 3*indices[0]+1, dForces(1,0))); triplets1.push_back(Trip(3*indices[j/3]+kj, 3*indices[0]+2, dForces(2,0))); triplets1.push_back(Trip(3*indices[j/3]+kj, 3*indices[1], dForces(0,1))); triplets1.push_back(Trip(3*indices[j/3]+kj, 3*indices[1]+1, dForces(1,1))); triplets1.push_back(Trip(3*indices[j/3]+kj, 3*indices[1]+2, dForces(2,1))); triplets1.push_back(Trip(3*indices[j/3]+kj, 3*indices[2], dForces(0,2))); triplets1.push_back(Trip(3*indices[j/3]+kj, 3*indices[2]+1, dForces(1,2))); triplets1.push_back(Trip(3*indices[j/3]+kj, 3*indices[2]+2, dForces(2,2))); triplets1.push_back(Trip(3*indices[j/3]+kj, 3*indices[3], dForces(0,3))); triplets1.push_back(Trip(3*indices[j/3]+kj, 3*indices[3]+1, dForces(1,3))); triplets1.push_back(Trip(3*indices[j/3]+kj, 3*indices[3]+2, dForces(2,3))); dx(j) = 0; } } forceGradient.setFromTriplets(triplets1.begin(), triplets1.end()); return; }
bool Plan_File::Read (long offset) { //---- check the file status ---- if (!Check_File ()) return (false); if (plan == NULL) return (Status (RECORD_SIZE)); if (File_Access () != READ) return (Status (ERROR)); //---- move to a specified location in the file ---- if (offset >= 0) { if (!Offset (offset)) return (false); } //---- allocate space ---- if (allocate_memory) { if (!Setup_Record ()) return (false); } //---- read the next plan ---- if (Record_Format () == BINARY) { int num_token; if (!Db_File::Read (plan, (sizeof (Plan_Data) - sizeof (int)))) return (false); if (time_sort) { int temp = plan->key1; plan->key1 = plan->key2; plan->key2 = temp; } num_record++; num_plan++; if (Leg () == 2) { num_trip++; } else if (Leg () == 1 && Trip () == 1) { num_traveler++; } num_token = Tokens (); if (num_token > 0) { if (!Check_Size (num_token)) return (false); if (!Db_File::Read (&(plan->data [0]), num_token * sizeof (int))) return (Status (PLAN_FIELDS)); num_record++; } return (true); } else { int field, max_field, value; char buffer [40], *ptr; field = max_field = 0; while (Db_File::Read ()) { num_record++; ptr = Clean_Record (); //---- check for a blank record ---- if (ptr == NULL || *ptr == '\0') continue; //---- process the plan record ---- while (ptr != NULL) { ptr = Get_Token (ptr, buffer, sizeof (buffer)); if (buffer [0] == '\0') break; field++; value = atol (buffer); switch (field) { case 1: //---- traveler id ---- Traveler (value); num_plan++; break; case 2: //---- user field ---- break; case 3: //---- trip id ---- Trip (value); break; case 4: //---- leg id ---- Leg (value); if (value == 2) { num_trip++; } else if (value == 1 && Trip () == 1) { num_traveler++; } break; case 5: //---- time ---- Time (value); break; case 6: //---- start id ---- Start_ID (value); break; case 7: //---- start type ---- Start_Type (value); break; case 8: //---- end id ---- End_ID (value); break; case 9: //---- end type ---- End_Type (value); break; case 10: //---- duration ---- Duration (value); break; case 11: //---- stop time ---- Stop_Time (value); break; case 12: //---- max time flag ---- break; case 13: //---- cost ---- Cost (value); break; case 14: //---- gcf ---- GCF (value); break; case 15: //---- driver flag ---- Driver_Flag (value); break; case 16: //---- mode ---- Mode (value); break; case 17: //---- number of tokens ---- if (value < 0) { Status (PLAN_FIELDS); return (false); } Tokens (value); max_field = value + 17; if (value == 0) return (true); if (!Check_Size (value)) return (false); break; default: //---- token value ---- if (field > max_field) { Status (PLAN_FIELDS); return (false); } plan->data [field - 18] = value; if (field == max_field) return (true); break; } } } if (field != 0) { return (Status (PLAN_FIELDS)); } return (false); } }
bool Plan_File::Write (Plan_Data *data) { int num_token; FILE *file; //---- check the file status ---- if (!Check_File ()) return (false); if (File_Access () == READ) return (Status (ERROR)); Plan_Data *backup = NULL; if (data != NULL) { backup = plan; plan = data; } else { if (plan == NULL) return (Status (RECORD_SIZE)); } //---- write the plan data ---- file = File (); num_token = Tokens (); if (Record_Format () == BINARY) { if (time_sort) { int size, temp; size = sizeof (Plan_Data) - sizeof (int); memcpy (backup, plan, size); temp = backup->key1; backup->key1 = backup->key2; backup->key2 = temp; if (!Db_File::Write (backup, size)) goto reset; } else { if (!Db_File::Write (plan, (sizeof (Plan_Data) - sizeof (int)))) goto reset; } num_record++; num_plan++; if (Leg () == 2) { num_trip++; } else if (Leg () == 1 && Trip () == 1) { num_traveler++; } if (num_token > 0) { if (!Db_File::Write (&(plan->data [0]), num_token * sizeof (int))) goto reset; num_record++; } } else { if (fprintf (file, "%d 0 %d %d\n%d %d %d %d %d\n%d %d %d %d %d\n%d %d\n%d\n", Traveler (), Trip (), Leg (), Time (), Start_ID (), Start_Type (), End_ID (), End_Type (), Duration (), Stop_Time (), 1, Cost (), GCF (), Driver_Flag (), Mode (), num_token) < 0) goto reset; num_record += 5; num_plan++; if (Leg () == 2) { num_trip++; } else if (Leg () == 1 && Trip () == 1) { num_traveler++; } //---- write tokens ---- if (num_token > 0) { int field; int i = 0; switch (Mode ()) { case AUTO_MODE: //---- auto ---- if (Driver_Flag ()) { //---- vehicle ID and number of passengers ---- i = 2; if (fprintf (file, "%d %d\n", plan->data [0], plan->data [1]) < 0) goto reset; num_record++; } break; case TRANSIT_MODE: //---- transit ---- if (Driver_Flag ()) { //---- schedule pairs, vehicle ID, and route ID ---- i = 3; if (fprintf (file, "%d %d %d\n", plan->data [0], plan->data [1], plan->data [2]) < 0) goto reset; num_record++; } break; default: break; } //---- print the rest of the fields in groups of 10 ---- for (field=0; i < num_token; i++, field++) { if (!field) { if (fprintf (file, "%d", plan->data [i]) < 0) goto reset; num_record++; } else if (!(field % 10)) { if (fprintf (file, "\n%d", plan->data [i]) < 0) goto reset; num_record++; } else { if (fprintf (file, " %d", plan->data [i]) < 0) goto reset; } } if (field) { if (fprintf (file, "\n") < 0) goto reset; } } //---- add a blank line at the end of the plan ---- if (fprintf (file, "\n") < 0) goto reset; num_record++; Flush (); } if (data != NULL) { plan = backup; } return (true); reset: if (data != NULL) { plan = backup; } return (false); }