Example #1
0
/// Graph plotting function
void goplot(){
	int j,k;
	int n= nodes;
	char buffer[24];
	gedge** matrix = output;
	/*
	gedge matrix[n][n];
	for(j=0;j<nodes;j++){
		for(k=0;k<nodes;k++){
			if(j!=k){//j!=k&&j!=k-1&&k!=j-1&&j!=k-3&&k!=j-3){
				matrix[j][k].weight=j+k+j;
				matrix[j][k].visited=0;
				}
			else{
				matrix[j][k].weight=0;
				matrix[j][k].visited=0;
				}
			}
		}*/
	for(j=0;j<nodes;j++){
		for(k=0;k<nodes;k++){
			if(matrix[j][k].weight!=-1){
	   			if(matrix[j][k].weight==matrix[k][j].weight){
	   				if(j<k){
	   					sprintf(buffer, "<->%.3f",matrix[j][k].weight);
	   					if(showWeights){
	   						write_strings( buffer ,(((array[j].x)+(array[k].x))/2)+10,(((array[k].y)+(array[j].y))/2)+10);
	   					}
						drawOneLine (array[j].x,array[j].y,array[k].x,array[k].y);
	   					}
	   				}
				else{
					if(j>k){
						sprintf(buffer, "->%.3f",matrix[j][k].weight);
	   					if(showWeights){
	   						write_strings( buffer ,(((array[j].x)+(array[k].x))/2)+10,(((array[k].y)+(array[j].y))/2)+10);
						}
						drawOneLine (array[j].x,array[j].y,array[k].x,array[k].y);
						}
					else{
						sprintf(buffer, "<-%.3f",matrix[j][k].weight);
	   					if(showWeights){
	   						write_strings( buffer ,(((array[j].x)+(array[k].x))/2)-10,(((array[k].y)+(array[j].y))/2)-10);
						}
						drawOneLine (array[j].x,array[j].y,array[k].x,array[k].y);
						}
					}
				}
			}
		}
	}
Example #2
0
void node::print(ostream &cout) const {
   cout << "--> node " << get_translated_id() << "/(id " << get_id() << ") <--"
        << endl;

   for (size_t i(0); i < theProgram->num_predicates(); ++i) {
      predicate *pred(theProgram->get_sorted_predicate(i));

      vector<string> vec;
      if (pred->is_persistent_pred())
         vec = pers_store.print(pred);
      else {
         if (linear.stored_as_hash_table(pred)) {
            const hash_table *table(
                linear.get_hash_table(pred->get_linear_id()));
            for (hash_table::iterator it(table->begin()); !it.end(); ++it) {
               const intrusive_list<vm::tuple> *ls(db::hash_table::underlying_list(*it));
               if (!ls->empty()) {
                  for (intrusive_list<vm::tuple>::const_iterator
                           it(ls->begin()),
                       end(ls->end());
                       it != end; ++it)
                     vec.push_back((*it)->to_str(pred));
               }
            }
         } else {
            const intrusive_list<vm::tuple> *ls(
                linear.get_linked_list(pred->get_linear_id()));
            if (ls && !ls->empty()) {
               for (intrusive_list<vm::tuple>::iterator it(ls->begin()),
                    end(ls->end());
                    it != end; ++it) {
                  auto s((*it)->to_str(pred));
                  vec.push_back(s);
               }
            }
         }
      }

      if (vec.empty()) continue;

      cout << " ";
      pred->print_simple(cout);
      cout << endl;

      sort(vec.begin(), vec.end());
      write_strings(vec, cout, 1);
   }
}