Boost logo

Boost Users :

From: Adel Essafi (adel.essafi_at_[hidden])
Date: 2004-06-04 01:08:21


hi list
I am developping a scheduling algorithm using boost When probleme is
that I want to use the adresses of boost nodes. I have writen this code.
then I put the node number 2 in the ready tasks list and the iterator
make the next iteration , I found that the node number 3 is in the ready
list.
any advice will be helpful
thanks

void allocate2(Graph &g,vector<MACHINE> &m,fstream &f){

  ///////////////////////////// declarations
///////////////////////////////
  cerr << "in function allocate 2 " << endl;
  typedef typename property_map<Graph, vertex_first_name_t>::type NamePA;
  NamePA name = get(vertex_first_name, g);
  typedef typename boost::property_traits<NamePA>::value_type NameType;
  typename boost::property_map<Graph, vertex_index_t>::type id =
get(vertex_index, g);
  typedef typename boost::graph_traits<Graph>::vertex_descriptor vertex;

  NameType src_name;
  typename boost::graph_traits<Graph>::vertex_iterator vi;

  list<vertex*> readyTasks;
  ///////////////////////// initialisation /////////////////////
  for (vi=vertices(g).first;vi!=vertices(g).second;++vi){
        if (in_degree(*vi,g)==0){
             vertex v = *vi;
             readyTasks.push_back(&v);
          }
    }

  for (list<vertex*>::iterator it=readyTasks.begin();
   it!=readyTasks.end();
    ++it){
       vertex *temp = *it;
       cerr << name[*temp].Id()<< endl;
    }
   while(readyTasks.size()){

       vertex *head=readyTasks.front();
       vector<int> times(m.size());
       //////////////// determine the best allocations time
       for (int i=0;i<m.size();i++){
           times[i]=(m[i]).bestAlloc(name[*head]);
        }
       /////////////// the minimum
       int min = *min_element(times.begin(),times.end());
       cerr << "min = "<<min<<endl;
       list<int>macs;
       for(int j=0;j<m.size();j++){
           if(times[j]==min) macs.push_back(j);
        }
        int Nmacs=macs.size();
        vector<int> penal(Nmacs);
        ////////////////// get pinalities
        int x=0;
        for (list<int>::iterator it=macs.begin();
             it!=macs.end();
             ++it,x++){
                  int nummac = *it;
                  if (m[nummac].type()) penal[x]=m[nummac].getPenal(min);
                  else penal[x]=100000;
               }
        ///////////////// get the best machine
        int minPenal = *min_element(penal.begin(),penal.end());
        //////////////// select machine
        int par=0;
        for (;(par<macs.size())&&(penal[par]!=minPenal);par++);
        m[par].affect(name[*head],min);
        updateTLevels(g,*head,min);
      
       readyTasks.erase(readyTasks.begin());

       for (vi=vertices(g).first;vi!=vertices(g).second;++vi){
          vertex current = *vi;
          cerr << "traitement du noeud "<<name[current].Id()<< endl;
          if (isReady(current,g)){ ////////// si la tache est prete
                   cerr << "\ttraitement du noeud pret
"<<name[current].Id()<< endl;
                   bool trouv=false;
                   for (list<vertex*>::iterator
itr=readyTasks.begin();itr!=readyTasks.end();++itr){
                      vertex *currentRt = *itr;
                      cerr << "\t\ttraitement de la tache
"<<name[*currentRt].Id()<< endl;
                      if(name[*currentRt].Id()==name[current].Id())
trouv=true;
                   }
                   if (!trouv){ //tache inexistante
                        if(name[current].Scheduled()==false){
                              readyTasks.push_back(&current);
                              cerr << "\tpush vertex "<<
name[current].Id()<<endl;
                            }
                     }
          }
        }
      }
}


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net