Example #1
0
void corrobj::get_seclist(
        double ra, double dec, float DA, vector <uint64> &idlist, 
        vector<int> &seclist, vector<float> &radlist)
{

    double sra, sdec;

    if (seclist.size() > 0) {
        //printf("Truncating seclist\n");
        seclist.resize(0);
    }
    if (radlist.size() > 0) {
        //printf("Truncating radlist\n");
        radlist.resize(0);
    }
    // Now loop over leaf ids and get the sources
    for(int i=0; i<idlist.size();i++)
    {

        int leafId = idlist[i];

        // Convert leafid into bin number
        int leafBin = idlist[i] - min_htmind;


        // Check if there are sources in this leafid
        if ( leafId >= min_htmind  &&  leafId <= max_htmind)
        {

            // Look for sources in this triangle
            if (rev[leafBin] != rev[leafBin+1]) 
            {

                int nLeafBin = rev[leafBin+1] - rev[leafBin];

                // Loop over sources in this leaf
                for(int iphot=0;iphot<nLeafBin;iphot++)
                {

                    int photUse = rev[ rev[leafBin]+iphot ];

                    if (par.corrtype == 1 || par.corrtype == 3)
                    {
                        sra  = secondary[photUse].ra;
                        sdec = secondary[photUse].dec;
                    }
                    else
                    {
                        sra  = random_secondary[photUse].ra;
                        sdec = random_secondary[photUse].dec;
                    }


                    double R = gcirc(ra, dec, sra, sdec);

                    // Mpc
                    float Rmpc = R*DA;

                    // convert to comoving?
                    //if (par.comoving) 
                    //  Rmpc = Rmpc*(1+z);


                    // Within our circular radius as well as lower limit
                    // in angular radius?
                    if (Rmpc >= par.rmin && Rmpc <= par.rmax && R > MINIMUM_ANGLE)
                    {
                        seclist.push_back(photUse);
                        radlist.push_back(Rmpc);
                    } // radius within circular radius min/max?

                } // loop over secondaries found

            } // any secondaries found in this leaf?

        } // leaf id is in allowed range?

    } // loop over found leaf ids


}
Example #2
0
  ShiftSched(int _staff, int _shifts, int _acts, vec< vec<int> >& _demand, int mode)
      : staff(_staff), shifts(_shifts), acts(_acts), dom(acts+maxG), demand(_demand)
  {
    for(int ww = 0; ww < staff; ww++)
    {
      xv.push();
      for( int ss = 0; ss < shifts; ss++ )
      {
          xv[ww].push(newIntVar(0,dom-1));
          xv[ww][ss]->specialiseToEL();
      }
    }
    
    // Build the grammar 
    int first = 0;
    while(first < shifts)
    {
      for(int ii = 0; ii < acts; ii++)
      {
        if(demand[first][ii])
          goto found_first;
      }
      first++;
    }
found_first:

    int last = first;
    for(int ss = first; ss < shifts; ss++)
    {
      for(int ii = 0; ii < acts; ii++)
      {
        if(demand[ss][ii])
        {
          last = ss;
          break;
        }
      }
    }
    CFG::CFG g( buildSchedG(acts, first, last) ); 
    
    // Construct variables for the circuit
    MDDTable mdd_tab(shifts);
    std::vector< std::vector<MDD> > seq;
    for(int ii = 0; ii < shifts; ii++)
    {
      seq.push_back( std::vector<MDD>() );
      for(int kk = 0; kk < dom; kk++)
      {
        seq[ii].push_back(mdd_tab.vareq(ii, kk));
      }
    }
    MDD gcirc(parseCYK(mdd_tab.fff(), seq, g));
    
    // Convert the MDD into an edge-valued graph.
    vec<int> slot_cost;
    for(int si = 0; si < acts; si++)
      slot_cost.push(1);
    for(int si = acts; si < dom; si++)
      slot_cost.push(0);

    EVLayerGraph graph;
    EVLayerGraph::NodeID gcirc_evgraph(mdd_to_layergraph(graph, gcirc, slot_cost));
    
    // Enforce the schedule for each worker.
    MDDOpts mopts;
    mopts.expl_strat = MDDOpts::E_KEEP;
    mopts.expl_alg = MDDOpts::E_MINIMAL;
    for(int ww = 0; ww < staff; ww++)
    {
      staff_cost.push(newIntVar(0, shifts));
      evgraph_to_wmdd(xv[ww], staff_cost[ww], graph, gcirc_evgraph, mopts);
    }

    for(int ww = 1; ww < staff; ww++)
      lex(xv[ww-1],xv[ww],false);

    // Enforce coverage constraints.
    for(int ss = 0; ss < shifts; ss++)
    {
      for(int act = 0; act < acts; act++)
      {
        vec<BoolView> bv;
        for(int ww = 0; ww < staff; ww++)
        {
          bv.push(xv[ww][ss]->getLit(act,1));
        }
        
          bool_linear_decomp(bv, IRT_GE, demand[ss][act]);
//          IntVar* d_const = newIntVar(demand[ss][act], demand[ss][act]);
//          bool_linear(bv, IRT_GE, d_const);
      }
    }
  
    unsigned int cMin(0); 
    for(int ss = 0; ss < shifts; ss++)
    {
      for(int aa = 0; aa < acts; aa++)
      {
        cMin += demand[ss][aa];
      }
    }

    cost = newIntVar(cMin, (last - first + 1)*staff);
    int_linear(staff_cost, IRT_LE, cost);

#if 0
    vec<IntVar*> rostered_int;
    for(int ss = 0; ss < shifts; ss++)
    {
      if(ss < first || ss > last)
        continue;

      for(int ww = 0; ww < staff; ww++)
      {
        IntVar* sv = newIntVar(0,1);
        bool2int(xv[ww][ss]->getLit(acts-1,3),sv);
        rostered_int.push(sv);
      }
    }
    int_linear(rostered_int, IRT_GE, cost);
#endif

    vec<IntVar*> vs;
    for(int ss = 0; ss < shifts; ss++)
    {
      for(int ww = 0; ww < staff; ww++)
      {
        vs.push(xv[ww][ss]);
      }
    }

    branch(vs, VAR_INORDER, VAL_MAX);
		optimize(cost, OPT_MIN);
    
//    vs.push(cost);
    output_vars(vs);
  }