Exemplo n.º 1
0
list<Task> DataStorage::load (TimePeriod period)
{
	list<Task> taskList;
	list<TaskNode*>::iterator iter;
	list<TaskNode*>::iterator endIter = _indxTasks.end ();
	if ((period.get_start_time ().get_date () == Time::DFLT_DATE && period.get_end_time ().get_date () == Time::DFLT_DATE) ||
		(period.get_start_time ().get_date () == Time::INF_DATE && period.get_end_time ().get_date () == Time::INF_DATE)) {
		for (iter = _indxTasks.begin (), iter++; iter != endIter; iter++) {
			if ((*iter)->_active)
				taskList.push_back ((*iter)->_task);
		}
	} else {
		bool clash = false;
		for (iter = _indxTasks.begin (); iter != endIter; iter++) {
			if ((*iter)->_active) {
				if ((*iter)->_task.timeTask)
					clash = checkTimeClash (*iter, &period);
				else
					clash = checkPeriodClash (*iter, &period);
			}

			if (clash == true) {
				taskList.push_back ((*iter)->_task);
				clash = false;
			}
		}
	}

	return taskList;
}
Exemplo n.º 2
0
		TimePeriod intersection(const TimePeriod& tp1, const TimePeriod& tp2)
		{
			if( !intersect(tp1, tp2) )
			{
				return TimePeriod(DateTime::getNADT(), DateTime::getNADT());
			}

			return TimePeriod(std::max(tp1.begin(), tp2.begin()), std::min(tp1.end(), tp2.end()));
		}
Exemplo n.º 3
0
		TimePeriod span(const TimePeriod& tp1, const TimePeriod& tp2)
		{
			if( isInvalid(tp1) || isInvalid(tp2) )
			{
				return TimePeriod(DateTime::getNADT(), DateTime::getNADT());
			}

			return TimePeriod(std::min(tp1.begin(), tp2.begin()), std::max(tp1.end(), tp2.end()));
		}
Exemplo n.º 4
0
		bool intersect(const TimePeriod& tp1, const TimePeriod& tp2)
		{
			if( isInvalid(tp1) || isInvalid(tp2) )
			{
				return false;
			}

			return ((tp1.end() > tp2.begin()) && (tp1.begin() < tp2.end()));
		}
Exemplo n.º 5
0
		TimePeriod merge(const TimePeriod& tp1, const TimePeriod& tp2)
		{
			if( isInvalid(tp1) || isInvalid(tp2) )
			{
				return TimePeriod(DateTime::getNADT(), DateTime::getNADT());
			}
			else if( intersect(tp1, tp2) || (tp1.end() == tp2.begin()) || (tp1.begin() == tp2.begin()) )
			{
				return TimePeriod(std::min(tp1.begin(), tp2.begin()), std::max(tp1.end(), tp2.end()));
			}

			return TimePeriod(DateTime::getNADT(), DateTime::getNADT());
		}
Exemplo n.º 6
0
		bool TimePeriod::contains(const TimePeriod& tp) const
		{
			if( isInvalid(m_start) && !isInvalid(tp.m_start) )
			{
				return false;
			}
			if( tp.empty() )
			{
				return true;
			}
			return (m_start <= tp.m_start) && (tp.m_finish <= m_finish);
		}
Exemplo n.º 7
0
bool Contest::giftIsGiven(TimePeriod tp, u_int gid) {

  bool status = false;
  stringstream debug;

  string prefix = "period", qtyname = "qty_rem";
	map<string, giftDetails> *
  dayprizes = Prizes.selectObjects(tp.getBeginTS(),
                                    prefix, qtyname);

	map<string, giftDetails>::iterator g;
	g = dayprizes->begin();

	while (g != dayprizes->end()) {
		if (gid == g->second.getGiftId() && g->second.getCurrentQuantity() == 0) {
      debug.str("");
      debug << "Contest::giftIsGiven(): gift " << gid << " is already given in this period." << endl;
      logMsg(debug.str());
      return true;
    }
  }

	return status;
}
Exemplo n.º 8
0
 void setValidRange(const TimePeriod& t) { validRange=TimePeriod(t.getStart(), t.getEnd()); }
Exemplo n.º 9
0
bool AztecOOSolver::solve()
{
  _F_
#ifdef HAVE_AZTECOO
  assert(m != NULL);
  assert(rhs != NULL);
  assert(m->size == rhs->size);

  TimePeriod tmr;

  // no output
  aztec.SetAztecOption(AZ_output, AZ_none);	// AZ_all | AZ_warnings | AZ_last | AZ_summary

#if !defined(H2D_COMPLEX) && !defined(H3D_COMPLEX)
  // setup the problem
  aztec.SetUserMatrix(m->mat);
  aztec.SetRHS(rhs->vec);
  Epetra_Vector x(*rhs->std_map);
  aztec.SetLHS(&x);

#ifdef HAVE_TEUCHOS
  if (!pc.is_null())
#else
  if (pc != NULL)
#endif
  {
    Epetra_Operator *op = pc->get_obj();
    assert(op != NULL);		// can work only with Epetra_Operators
    aztec.SetPrecOperator(op);
  }

  // solve it
  aztec.Iterate(max_iters, tolerance);

  tmr.tick();
  time = tmr.accumulated();

  delete [] sln;
  sln = new scalar[m->size];
  MEM_CHECK(sln);
  memset(sln, 0, m->size * sizeof(scalar));

  // copy the solution into sln vector
  for (unsigned int i = 0; i < m->size; i++) sln[i] = x[i];
#else
  double c0r = 1.0, c0i = 0.0;
  double c1r = 0.0, c1i = 1.0;

  Epetra_Vector xr(*rhs->std_map);
  Epetra_Vector xi(*rhs->std_map);

  Komplex_LinearProblem kp(c0r, c0i, *m->mat, c1r, c1i, *m->mat_im, xr, xi, *rhs->vec, *rhs->vec_im);
  Epetra_LinearProblem *lp = kp.KomplexProblem();
  aztec.SetProblem(*lp);

  // solve it
  aztec.Iterate(max_iters, tolerance);

  kp.ExtractSolution(xr, xi);

  delete [] sln;
  sln = new scalar[m->size];
  MEM_CHECK(sln);
  memset(sln, 0, m->size * sizeof(scalar));

  // copy the solution into sln vector
  for (unsigned int i = 0; i < m->size; i++) sln[i] = scalar(xr[i], xi[i]);
#endif
  return true;
#else
  return false;
#endif
}
Exemplo n.º 10
0
int Contest::handle_timeout(const ACE_Time_Value &tv,
																			const void *argument) {

	ACE_Guard<ACE_Thread_Mutex> guard(mutex_); {
    // Disable Transactions as we're about to write data to the DB
    if (dbconnection)
  	  dbconnection->disableTransactions();

		TimePeriod tp;
    int arg = (int)(argument);

#ifdef DEBUG
    stringstream debug;
    debug.str("");
#endif

		if (arg == ID_SOC) {
			logMsg("Contest::handle_timeout(): Start of Contest timer\n");
      init();
  	}
		
	 	if (arg == ID_EOC) {
 			logMsg("Contest::handle_timeout(): End of Contest timer\n");
 			preparetoShutdown();
	 	}

 		if ((arg == ID_EOD) || (arg == ID_EOW) || (arg == ID_EOM)) {
			logMsg("Contest::handle_timeout(): End of day timer\n");
			tp = TimePeriod(EOD[current_day], EOD[current_day+1]);
      current_day++;
 		}

	 	if (arg == ID_EOW) {
 			logMsg("Contest::handle_timeout(): End of week timer\n");
     	tp = TimePeriod(EOW[current_week], EOW[current_week+1]);
			current_week++;
 		}

	 	if (arg == ID_EOM) {
 			logMsg("Contest::handle_timeout(): End of month timer\n");
     	tp = TimePeriod(EOM[current_month], EOM[current_month+1]);
			current_month++;
		}

		if (arg != ID_SOC) {
			tp = TimePeriod(SOC, tp.getEndTS());
      if (tp.getEndTS().nextDay() >= time(0)) {
#ifdef EXTRADEBUG
        debug.str("");
        debug << "Contest::handle_timeout(): tp.getEndTS().nextDay() = " << tp.getEndTS().nextDay()
              << ", time(0) = " << time(0) << endl;
		    logMsg(debug.str());
#endif
      }
      dbconnection->changeLogFilename();
		}

    if (current_day < EOD.size()) {
			TimeStamp ts(EOD[current_day]);	
			// Create Day Object (the constructor writes to the DB)
#ifdef DEBUG
      debug.str("");
      debug << "Transactions enabled: " << boolalpha
            << dbconnection->transactionsEnabled() << endl;
      logMsg(debug.str());
#endif
			Day *newday = new Day(this, ts);
		  ContestDays.push_back(*newday);
#ifdef DEBUG
      debug.str("");
      debug << "Contest::handle_timeout(): ContestDays.size() = " << ContestDays.size() << endl;
      debug << "Waiting for today's traffic..." << endl;
		  logMsg(debug.str());
#endif 
  		delete newday;
    }
    // Enable Transactions again
    if (dbconnection)
      dbconnection->enableTransactions();
	}

  return 0;
}
Exemplo n.º 11
0
double KellyTypeAdapt::calc_err_internal(Hermes::vector<Solution *> slns,
                                         Hermes::vector<double>* component_errors,
                                         unsigned int error_flags)
{    
  int n = slns.size();
  error_if (n != this->num,
            "Wrong number of solutions.");

  TimePeriod tmr;

  for (int i = 0; i < n; i++)
  {
    this->sln[i] = slns[i];
    sln[i]->set_quad_2d(&g_quad_2d_std);
  }

  have_coarse_solutions = true;
  
  WeakForm::Stage stage;

  num_act_elems = 0;
  for (int i = 0; i < num; i++)
  {
    stage.meshes.push_back(sln[i]->get_mesh());
    stage.fns.push_back(sln[i]);

    num_act_elems += stage.meshes[i]->get_num_active_elements();
    int max = stage.meshes[i]->get_max_element_id();

    if (errors[i] != NULL) delete [] errors[i];
    errors[i] = new double[max];
    memset(errors[i], 0.0, sizeof(double) * max);
  }
/*
  for (unsigned int i = 0; i < error_estimators_vol.size(); i++)
    trset.insert(error_estimators_vol[i].ext.begin(), error_estimators_vol[i].ext.end());
  for (unsigned int i = 0; i < error_estimators_surf.size(); i++)
    trset.insert(error_estimators_surf[i].ext.begin(), error_estimators_surf[i].ext.end());
*/

  double total_norm = 0.0;

  bool calc_norm = false;
  if ((error_flags & HERMES_ELEMENT_ERROR_MASK) == HERMES_ELEMENT_ERROR_REL ||
      (error_flags & HERMES_TOTAL_ERROR_MASK) == HERMES_TOTAL_ERROR_REL) calc_norm = true;

  double *norms = NULL;
  if (calc_norm)
  {
    norms = new double[num];
    memset(norms, 0.0, num * sizeof(double));
  }

  double *errors_components = new double[num];
  memset(errors_components, 0.0, num * sizeof(double));
  this->errors_squared_sum = 0.0;
  double total_error = 0.0;

  bool bnd[4];          // FIXME: magic number - maximal possible number of element surfaces
  SurfPos surf_pos[4];
  Element **ee;
  Traverse trav;

  // Reset the e->visited status of each element of each mesh (most likely it will be set to true from
  // the latest assembling procedure).
  if (ignore_visited_segments)
  {
    for (int i = 0; i < num; i++)
    {
      Element* e;
      for_all_active_elements(e, stage.meshes[i])
        e->visited = false;
    }
  }
  
  //WARNING: AD HOC debugging parameter.
  bool multimesh = false;

  // Begin the multimesh traversal.
  trav.begin(num, &(stage.meshes.front()), &(stage.fns.front()));
  while ((ee = trav.get_next_state(bnd, surf_pos)) != NULL)
  {   
    // Go through all solution components.
    for (int i = 0; i < num; i++)
    {
      if (ee[i] == NULL)
        continue;
      
      // Set maximum integration order for use in integrals, see limit_order()
      update_limit_table(ee[i]->get_mode());

      RefMap *rm = sln[i]->get_refmap();

      double err = 0.0;

      // Go through all volumetric error estimators.
      for (unsigned int iest = 0; iest < error_estimators_vol.size(); iest++)
      {
        // Skip current error estimator if it is assigned to a different component or geometric area
        // different from that of the current active element.
        if (error_estimators_vol[iest]->i != i)
          continue;
        /*
        if (error_estimators_vol[iest].area != ee[i]->marker)
          continue;
          */
        else if (error_estimators_vol[iest]->area != HERMES_ANY)
          continue;

        err += eval_volumetric_estimator(error_estimators_vol[iest], rm);
      }

      // Go through all surface error estimators (includes both interface and boundary est's).
      for (unsigned int iest = 0; iest < error_estimators_surf.size(); iest++)
      {
        if (error_estimators_surf[iest]->i != i)
          continue;

        for (int isurf = 0; isurf < ee[i]->get_num_surf(); isurf++)
        {
            /*
          if (error_estimators_surf[iest].area > 0 &&
              error_estimators_surf[iest].area != surf_pos[isurf].marker) continue;
          */
          if (bnd[isurf])   // Boundary
          {
            if (error_estimators_surf[iest]->area == H2D_DG_INNER_EDGE) continue;
            
            /*
            if (boundary_markers_conversion.get_internal_marker(error_estimators_surf[iest].area) < 0 &&
                error_estimators_surf[iest].area != HERMES_ANY) continue;
            */    
            
            err += eval_boundary_estimator(error_estimators_surf[iest], rm, surf_pos);
          }
          else              // Interface
          {
            if (error_estimators_surf[iest]->area != H2D_DG_INNER_EDGE) continue;

            /* BEGIN COPY FROM DISCRETE_PROBLEM.CPP */
            
            // 5 is for bits per page in the array.
            LightArray<NeighborSearch*> neighbor_searches(5);
            unsigned int num_neighbors = 0;
            DiscreteProblem::NeighborNode* root;
            int ns_index;
            
            dp.min_dg_mesh_seq = 0;
            for(int j = 0; j < num; j++)
              if(stage.meshes[j]->get_seq() < dp.min_dg_mesh_seq || j == 0)
                dp.min_dg_mesh_seq = stage.meshes[j]->get_seq();
            
            ns_index = stage.meshes[i]->get_seq() - dp.min_dg_mesh_seq; // = 0 for single mesh
            
            // Determine the minimum mesh seq in this stage.
            if (multimesh) 
            {              
              // Initialize the NeighborSearches.
              dp.init_neighbors(neighbor_searches, stage, isurf);
              
              // Create a multimesh tree;
              root = new DiscreteProblem::NeighborNode(NULL, 0);
              dp.build_multimesh_tree(root, neighbor_searches);
              
              // Update all NeighborSearches according to the multimesh tree.
              // After this, all NeighborSearches in neighbor_searches should have the same count 
              // of neighbors and proper set of transformations
              // for the central and the neighbor element(s) alike.
              // Also check that every NeighborSearch has the same number of neighbor elements.
              for(unsigned int j = 0; j < neighbor_searches.get_size(); j++)
                if(neighbor_searches.present(j)) {
                  NeighborSearch* ns = neighbor_searches.get(j);
                  dp.update_neighbor_search(ns, root);
                  if(num_neighbors == 0)
                    num_neighbors = ns->n_neighbors;
                  if(ns->n_neighbors != num_neighbors)
                    error("Num_neighbors of different NeighborSearches not matching in KellyTypeAdapt::calc_err_internal.");
                }
            }
            else
            {
              NeighborSearch *ns = new NeighborSearch(ee[i], stage.meshes[i]);
              ns->original_central_el_transform = stage.fns[i]->get_transform();
              ns->set_active_edge(isurf);
              ns->clear_initial_sub_idx();
              num_neighbors = ns->n_neighbors;
              neighbor_searches.add(ns, ns_index);
            }

            // Go through all segments of the currently processed interface (segmentation is caused
            // by hanging nodes on the other side of the interface).
            for (unsigned int neighbor = 0; neighbor < num_neighbors; neighbor++)
            {              
              if (ignore_visited_segments) {
                bool processed = true;
                for(unsigned int j = 0; j < neighbor_searches.get_size(); j++)
                  if(neighbor_searches.present(j))
                    if(!neighbor_searches.get(j)->neighbors.at(neighbor)->visited) {
                      processed = false;
                      break;
                    }
                if (processed) continue;
              }
              
              // Set the active segment in all NeighborSearches
              for(unsigned int j = 0; j < neighbor_searches.get_size(); j++)
                if(neighbor_searches.present(j)) {
                  neighbor_searches.get(j)->active_segment = neighbor;
                  neighbor_searches.get(j)->neighb_el = neighbor_searches.get(j)->neighbors[neighbor];
                  neighbor_searches.get(j)->neighbor_edge = neighbor_searches.get(j)->neighbor_edges[neighbor];
                }
                
              // Push all the necessary transformations to all functions of this stage.
              // The important thing is that the transformations to the current subelement are already there.
              // Also store the current neighbor element and neighbor edge in neighb_el, neighbor_edge.
              if (multimesh) 
              {
                for(unsigned int fns_i = 0; fns_i < stage.fns.size(); fns_i++)
                  for(unsigned int trf_i = 0; trf_i < neighbor_searches.get(stage.meshes[fns_i]->get_seq() - dp.min_dg_mesh_seq)->central_n_trans[neighbor]; trf_i++)
                    stage.fns[fns_i]->push_transform(neighbor_searches.get(stage.meshes[fns_i]->get_seq() - dp.min_dg_mesh_seq)->central_transformations[neighbor][trf_i]);
              }
              else
              {            
                // Push the transformations only to the solution on the current mesh
                for(unsigned int trf_i = 0; trf_i < neighbor_searches.get(ns_index)->central_n_trans[neighbor]; trf_i++)
                  stage.fns[i]->push_transform(neighbor_searches.get(ns_index)->central_transformations[neighbor][trf_i]);
              }
              /* END COPY FROM DISCRETE_PROBLEM.CPP */
              rm->force_transform(this->sln[i]->get_transform(), this->sln[i]->get_ctm());
              
              // The estimate is multiplied by 0.5 in order to distribute the error equally onto
              // the two neighboring elements.
              double central_err = 0.5 * eval_interface_estimator(error_estimators_surf[iest],
                                                                  rm, surf_pos, neighbor_searches, 
                                                                  ns_index);
              double neighb_err = central_err;

              // Scale the error estimate by the scaling function dependent on the element diameter
              // (use the central element's diameter).
              if (use_aposteriori_interface_scaling && interface_scaling_fns[i])
                central_err *= interface_scaling_fns[i](ee[i]->get_diameter());

              // In the case this edge will be ignored when calculating the error for the element on
              // the other side, add the now computed error to that element as well.
              if (ignore_visited_segments)
              {
                Element *neighb = neighbor_searches.get(i)->neighb_el;

                // Scale the error estimate by the scaling function dependent on the element diameter
                // (use the diameter of the element on the other side).
                if (use_aposteriori_interface_scaling && interface_scaling_fns[i])
                  neighb_err *= interface_scaling_fns[i](neighb->get_diameter());

                errors_components[i] += central_err + neighb_err;
                total_error += central_err + neighb_err;
                errors[i][ee[i]->id] += central_err;
                errors[i][neighb->id] += neighb_err;
              }
              else
                err += central_err;
              
              /* BEGIN COPY FROM DISCRETE_PROBLEM.CPP */
              
              // Clear the transformations from the RefMaps and all functions.
              if (multimesh)
                for(unsigned int fns_i = 0; fns_i < stage.fns.size(); fns_i++)
                  stage.fns[fns_i]->set_transform(neighbor_searches.get(stage.meshes[fns_i]->get_seq() - dp.min_dg_mesh_seq)->original_central_el_transform);
              else
                stage.fns[i]->set_transform(neighbor_searches.get(ns_index)->original_central_el_transform);

              rm->set_transform(neighbor_searches.get(ns_index)->original_central_el_transform);

              
              /* END COPY FROM DISCRETE_PROBLEM.CPP */
            }
            
            /* BEGIN COPY FROM DISCRETE_PROBLEM.CPP */
            
            if (multimesh)
              // Delete the multimesh tree;
              delete root;
            
            // Delete the neighbor_searches array.
            for(unsigned int j = 0; j < neighbor_searches.get_size(); j++) 
              if(neighbor_searches.present(j))
                delete neighbor_searches.get(j);
              
            /* END COPY FROM DISCRETE_PROBLEM.CPP */
            
          }
        }
      }

      if (calc_norm)
      {
        double nrm = eval_solution_norm(error_form[i][i], rm, sln[i]);
        norms[i] += nrm;
        total_norm += nrm;
      }

      errors_components[i] += err;
      total_error += err;
      errors[i][ee[i]->id] += err;

      ee[i]->visited = true;
    }
  }
  trav.finish();

  // Store the calculation for each solution component separately.
  if(component_errors != NULL)
  {
    component_errors->clear();
    for (int i = 0; i < num; i++)
    {
      if((error_flags & HERMES_TOTAL_ERROR_MASK) == HERMES_TOTAL_ERROR_ABS)
        component_errors->push_back(sqrt(errors_components[i]));
      else if ((error_flags & HERMES_TOTAL_ERROR_MASK) == HERMES_TOTAL_ERROR_REL)
        component_errors->push_back(sqrt(errors_components[i]/norms[i]));
      else
      {
        error("Unknown total error type (0x%x).", error_flags & HERMES_TOTAL_ERROR_MASK);
        return -1.0;
      }
    }
  }

  tmr.tick();
  error_time = tmr.accumulated();

  // Make the error relative if needed.
  if ((error_flags & HERMES_ELEMENT_ERROR_MASK) == HERMES_ELEMENT_ERROR_REL)
  {
    for (int i = 0; i < num; i++)
    {
      Element* e;
      for_all_active_elements(e, stage.meshes[i])
        errors[i][e->id] /= norms[i];
    }
  }

  this->errors_squared_sum = total_error;

  // Element error mask is used here, because this variable is used in the adapt()
  // function, where the processed error (sum of errors of processed element errors)
  // is matched to this variable.
  if ((error_flags & HERMES_TOTAL_ERROR_MASK) == HERMES_ELEMENT_ERROR_REL)
    errors_squared_sum /= total_norm;

  // Prepare an ordered list of elements according to an error.
  fill_regular_queue(&(stage.meshes.front()));
  have_errors = true;

  if (calc_norm)
    delete [] norms;
  delete [] errors_components;

  // Return error value.
  if ((error_flags & HERMES_TOTAL_ERROR_MASK) == HERMES_TOTAL_ERROR_ABS)
    return sqrt(total_error);
  else if ((error_flags & HERMES_TOTAL_ERROR_MASK) == HERMES_TOTAL_ERROR_REL)
    return sqrt(total_error / total_norm);
  else
  {
    error("Unknown total error type (0x%x).", error_flags & HERMES_TOTAL_ERROR_MASK);
    return -1.0;
  }
}
void TimeHelpersTests::testRunningPeriod( TestReporter& reporter )
{
   NEW_TEST_FUNCTION( reporter );

   TimePeriod r;

   /** 
    *   No time supplied = not valid period.
    */
   
   CHECK( !r.isValid(), reporter );
   CHECK( r.length() == 0, reporter );
   
   r.updatePeriod( 1000 );

   /** 
    *   Only one time supplied = not valid period.
    */
   
   CHECK( !r.isValid(), reporter );
   CHECK( r.length() == 0, reporter );
   
   /** 
    *   Two times supplied = valid period.
    */
   
   r.updatePeriod( 2000 );
   
   CHECK( r.isValid(), reporter );
   
   CHECK( r.length() == 1000 , reporter );

   /** 
    *   Two times supplied, but the same = not valid period.
    */
   
   r.updatePeriod( 2000 );

   CHECK( !r.isValid(), reporter );
   CHECK( r.length() == 0, reporter );
   
   /** 
    *   Two times supplied, but the last < previous = not valid period.
    */

   r.updatePeriod( 1000 );

   CHECK( !r.isValid(), reporter );
   CHECK( r.length() == 0, reporter );
}
Exemplo n.º 13
0
		bool operator!=(const TimePeriod& tp1, const TimePeriod& tp2)
		{
			return (tp1.begin() != tp2.begin()) || (tp1.end() != tp2.end());
		}
Exemplo n.º 14
0
		bool operator==(const TimePeriod& tp1, const TimePeriod& tp2)
		{
			return (tp1.begin() == tp2.begin()) && (tp1.end() == tp2.end());
		}