previousnext
ASTL homeSTL home

intersection

Prototype

template <class DFA1,class DFA2,class DFA3
void intersection(DFA1 &fa1, DFA2 &fa2, DFA3 &result);

Description

Computes the intersection of fa1 and fa2 into result..

Definition

Defined in set_operation.h.

Requirements on types

Preconditions

None

Example

CODE

#include <tag.h>
#include <dfa_matrix.h>
#include <alphabet.h>
#include <iostream.h>
#include <language.h>
#include <minimize.h>
#include <astl_tree.h>
#include <vcg.h>
#include <set_operation.h>

main() 
{
//specifies the types
typedef DFA_matrix<Range_alphabet<char,'a','g'>,minimization_tag> DFA_type;
typedef istream_iterator<vector<typename DFA_type::Alphabet> > Entry;


//initialising the DFA, empty
DFA_type dfa1;
DFA_type dfa2;
DFA_type res;


//declaring streams
ifstream dico1,dico2;
ofstream vcg1,vcg2,vcgRes;

//first DFA
cout<<"first DFA"<<endl;
dico1.open("dico1");
tree_build(dfa1,Entry(dico1),Entry());
acyclic_minimization(dfa1);
language(dfa1,ostream_iterator<DFA_type::Alphabet>(cout));
vcg1.open("Idfa1.vcg",ios::out | ios::trunc);
vcg(dfa1,"First DFA",vcg1);
dico1.close();
vcg1.close();
cout<<endl;

//second DFA
cout<<"second DFA"<<endl;
dico2.open("dico2");
tree_build(dfa2,Entry(dico2),Entry());
acyclic_minimization(dfa2);
language(dfa2,ostream_iterator<DFA_type::Alphabet>(cout));
vcg2.open("Idfa2.vcg",ios::out | ios::trunc);
vcg(dfa2,"Second DFA",vcg2);
dico2.close();
vcg2.close();
cout<<endl;

//Union DFA
cout<<"now: INTERSECTION"<<endl;
intersection(dfa1,dfa2,res);
language(res,ostream_iterator<DFA_type::Alphabet>(cout));
vcgRes.open("IRes.vcg",ios::out | ios::trunc);
vcg(res,"INTERSECTION",vcgRes);
vcgRes.close();
cout<<endl;

REFORMATED OUTPUT
game
game
game
ghost
ghost
ghost
 
host
 
master
 
 
monster
  
  
role
role
role
  
ronin
 
rotten
 
 
 
samurai
 

Notes

See also

union, symetrical difference