Esempio n. 1
0
//checks if the first set is a subset of the second set
bool isSubset(intset& set1, intset& set2)
{
    for(intset::iterator it1 = set1.begin(); it1 != set1.end(); it1++)
        if(set2.find(*it1) == set2.end())
            return false;
    return true;
}
Esempio n. 2
0
static void test_iterators(intset &s)
{
   printf("iterator && const_iterator\n");
   // all iterators are different
   intset empty;
   assert(empty.begin()  != intset().begin());
   assert(empty.cbegin() != intset().cbegin());
   assert(empty.end()  != intset().end());
   assert(empty.cend() != intset().cend());

   // iteration through empty containers must not execute the loop body
   for (intset::iterator it = empty.begin(); it != empty.end(); ++it)
      assert(0);
   for (intset::iterator it = empty.end(); it-- != empty.begin();)
      assert(0);
   for (intset::const_iterator it = constify(empty).begin(); it != constify(empty).end(); ++it)
      assert(0);
   for (intset::const_iterator it = constify(empty).end(); it-- != constify(empty).begin();)
      assert(0);
   for (intset::const_iterator it = empty.cbegin(); it != empty.cend(); ++it)
      assert(0);
   for (intset::const_iterator it = empty.cend(); it-- != empty.cbegin();)
      assert(0);

   {
      intset::iterator it1 = s.begin();
      intset::iterator it2 = ++it1;
      assert(it1++ == it2);
      assert(--it1 == it2);
      assert(--it1 == --it2);
      ++it1;
      ++it2;
      assert(it1 == it2--);
      assert(s.begin() == it2);
   }
   {
      intset::const_iterator it1 = s.cbegin();
      intset::const_iterator it2 = ++it1;
      assert(it1++ == it2);
      assert(--it1 == it2);
      assert(--it1 == --it2);
      ++it1;
      ++it2;
      assert(it1 == it2--);
      assert(s.cbegin() == it2);
   }
   int i = 0;
   for (intset::iterator it = s.begin(); it != s.end(); ++it, ++i)
      assert(*it == i);

   for (intset::iterator it = s.end(); it-- != s.begin();)
   {
      --i;
      assert(*it == i);
   }
   i = 0;
   for (intset::const_iterator it = constify(s).begin(); it != constify(s).end(); ++it, ++i)
      assert(*it == i);

   for (intset::const_iterator it = constify(s).end(); it-- != constify(s).begin();)
   {
      --i;
      assert(*it == i);
   }
   i = 0;
   for (intset::const_iterator it = s.cbegin(); it != s.cend(); ++it, ++i)
      assert(*it.operator->() == i);
   for (intset::const_iterator it = s.cend(); it-- != s.cbegin();)
   {
      --i;
      assert(*it.operator->() == i);
   }
   for (intset::const_iterator it = s.cbegin(); it != s.cend(); ++it)
      printf(" {%d}", *it);
   printf("\n");
   for (intset::const_iterator it = s.cend(); it-- != s.cbegin();)
      printf(" {%d}", *it.operator->());
   printf("\n");
}
    SatelliteProblemDomainGenerator(int n_sat, int n_inst_type, int n_ant_type, int n_gs, int n_tw)
    : num_satellites(n_sat)
    , num_ground_statiion(n_gs)
    , num_antenna_types(n_ant_type)
    , num_instrument_types(n_inst_type)
    , num_timewindows(n_tw)
    , instrument_max_on_time(80)
    , instrument_min_off_time(5)
    {
        if (num_antenna_types < 1)
            num_antenna_types = 1;
        if (num_instrument_types < 1)
            num_instrument_types = 1;

        srand(time(NULL));


        for (int i = 0; i < num_antenna_types; i++)
        {
            ant_rate.push_back(get_rand_num(2, 5));
            ant_bat_rate.push_back(get_rand_num(2, 5));
            ant_angular_speed.push_back(get_rand_num(5, 10));
            ant_gs_map.push_back(intvector(num_ground_statiion, 0));
            ant_sat_map.push_back(intvector(num_satellites, 0));

            antennaTotal.insert(antennaTotal.end(), i);
        }
        //std::cout << "Antenna Total Size = " << antennaTotal.size() << std::endl;
        for (int i = 0; i < num_instrument_types; i++)
        {
            inst_rate.push_back(get_rand_num(3, 8));
            inst_bat_rate.push_back(get_rand_num(3, 8));
            inst_angular_speed.push_back(get_rand_num(5, 10));
            inst_sat_map.push_back(intvector(num_satellites, 0));

            instrumentTotal.insert(instrumentTotal.end(), i);
        }

        for (int i = 0; i < num_satellites; i++)
        {
            sat_unit_recharge.push_back(get_rand_num(15, 20));
            sat_storage_total.push_back(get_rand_num(150, 200));
            sat_battery_total.push_back(get_rand_num(350, 500));

            satellite_sun_visibility.push_back(std::vector<intpair>());
            int start = get_rand_num(0, 100);
            int length = get_rand_num(20, 30);
            for (int j = 0; j < num_timewindows; j++)
            {
                satellite_sun_visibility[i].push_back(std::make_pair<int, int>(start, start + length));
                start = start + length + 40;
            }

            /*
             * Each Satellite must support at least 2 instrument types
             */
            int instrumentNumber = get_rand_num(1, num_instrument_types);
            intset instsize = instrumentTotal;
            while (instrumentNumber > 0)
            {
                int selected = get_rand_num(0, instsize.size() - 1);
                intset::iterator itr = instsize.begin();
                int count = 0;
                while (itr != instsize.end())
                {
                    if (count == selected)
                    {
                        inst_sat_map[*itr][i] = 1;
                        //std::cout << "Satellite " << i << " will have instrument " << *itr << " = " << inst_sat_map[*itr][i] << std::endl;
                        instsize.erase(itr);
                        instrumentNumber--;
                        break;
                    }
                    itr++;
                    count++;
                }

            }


            /*
             * Each Satellite must support at least 2 antenna types;
             */
            int antNumber = get_rand_num(1, num_antenna_types);
            intset antsize = antennaTotal;
            while (antNumber > 0)
            {
                int selected = get_rand_num(0, antsize.size() - 1);
                intset::iterator itr = antsize.begin();
                int count = 0;
                while (itr != antsize.end())
                {
                    if (count == selected)
                    {
                        ant_sat_map[*itr][i] = 1;
                        //std::cout << "Satellite " << i << " will have antenna " << *itr << " = " << ant_sat_map[*itr][i] << std::endl;
                        antsize.erase(itr);
                        antNumber--;
                        break;
                    }
                    itr++;
                    count++;
                }

            }


            satellite_groundstation_visibility.push_back(std::vector< std::vector<intpair> >());
            for (int j = 0; j < num_ground_statiion; j++)
            {
                satellite_groundstation_visibility[i].push_back(std::vector<intpair>());
                int start = get_rand_num(0, 100);
                int length = get_rand_num(20, 30);
                for (int k = 0; k < num_timewindows; k++)
                {
                    satellite_groundstation_visibility[i][j].push_back(std::make_pair<int, int>(start, start + length));
                    start = start + length + 60;
                }
            }
        }


        for (int i = 0; i < num_ground_statiion; i++)
        {
            gs_angular_distance.push_back(intvector());
            for (int j = 0; j < num_ground_statiion; j++)
            {
                gs_angular_distance[i].push_back(0);
                if (i != j)
                {
                    gs_angular_distance[i][j] = get_manhattan_dist(get_rand_num(0, 100), get_rand_num(0, 100), get_rand_num(0, 100), get_rand_num(0, 100));
                }
            }

            /*
             * Each Ground Station must support at least 1 antenna type
             */
            int antNumber = get_rand_num(1, num_antenna_types);
            intset antsize = antennaTotal;
            while (antNumber > 0)
            {
                int selected = get_rand_num(0, antsize.size() - 1);
                intset::iterator itr = antsize.begin();
                int count = 0;
                while (itr != antsize.end())
                {
                    if (count == selected)
                    {
                        ant_gs_map[*itr][i] = 1;
                        //std::cout << "Ground Station " << i << " will have antenna " << *itr << " = " << ant_gs_map[*itr][i] << std::endl;
                        antsize.erase(itr);
                        antNumber--;
                        break;
                    }
                    itr++;
                    count++;
                }

            }
        }

        domain_name << "Sat-" << n_sat << "-GS-" << n_gs << "-Inst-" << n_inst_type << "-Ant-" << n_ant_type;
    }