Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes

chomp::multiwork::mwSubCoordinator< dim, coord > Class Template Reference

This class defines a coordinator for the multi-work subdivision framework. More...

#include <mwsubdiv.h>

Inheritance diagram for chomp::multiwork::mwSubCoordinator< dim, coord >:
chomp::multiwork::mwCoordinator chomp::multiwork::mwTask

List of all members.

Public Member Functions

 mwSubCoordinator ()
 The constructor of an uninitialized coordinator.
 mwSubCoordinator (const char *filename, int _inilevel, int _maxlevel, bool _flushfile, const double *_paramLeft, const double *_paramRight)
 The complete constructor of a coordinator object.
 ~mwSubCoordinator ()
 The destructor.

Private Types

typedef tCubeFix< dim, coord > ppCube
 The maximal feasible subdivision level.
typedef hashedset< ppCubeppCubes
 The type of a set of cubes in the parameter space.
typedef tRectangle< coord > ppRect
 The kind of rectangle used to iterate ranges of cubes.
typedef mwSubDataPack< dim, coord > ppPack
 The type of a sent data pack kept in an internal array.

Private Member Functions

int Prepare (mwData &data)
 A function for preparing data by a coordinator.
int Accept (mwData &data)
 A function for accepting results by a coordinator.
int Reject (mwData &data)
 A function for taking rejected data by a coordinator.
bool FindMinCube (const typename mwSubCoordinator< dim, coord >::ppCubes tab[], const typename mwSubCoordinator< dim, coord >::ppCubes sent[], int minlevel, int maxlevel, int &level, typename mwSubCoordinator< dim, coord >::ppCube &q)
 Finds a cube at the lowest level (>= min, < max) of the given set of cubes that was not sent, yet.
int Contained (const typename mwSubCoordinator< dim, coord >::ppCube &q, int level, const typename mwSubCoordinator< dim, coord >::ppCubes tab[], int minlevel) const
 Verifies if the given box is contained in a box at any level greater than or equal to the given minimum in the given family of boxes.
void NegativeProbe (const ppCube &q, int level)
 A function for acquiring a negative probe.
void GoodProbe (const ppCube &q, int level)
 A function for acquiring a good probe.
void FailedBox (const ppCube &q, int level)
 A function for acquiring a box for which the verification failed.
void SuccessfulBox (const ppCube &q, int level)
 A function for acquiring a successful box.
int ReadResults (std::istream &in)
 A procedure for reading the previously computed results.

Static Private Member Functions

static mwSubCoordinator< dim,
coord >::ppCube 
UpLevel (const typename mwSubCoordinator< dim, coord >::ppCube &q)
 Returns a probe with respect to a higher level grid, that is, multiplies all the coordinates by 2.
static mwSubCoordinator< dim,
coord >::ppCube 
UpLevel (const typename mwSubCoordinator< dim, coord >::ppCube &box, const typename mwSubCoordinator< dim, coord >::ppCube &corner)
 Returns a box with respect to a higher level grid which is contained in the given box and contains the given corner.
static mwSubCoordinator< dim,
coord >::ppCube 
DownLevel (const typename mwSubCoordinator< dim, coord >::ppCube &q)
 Returns a box with respect to a higher level grid which contains the given box, that is, divides all the coordinates by 2.

Private Attributes

ppCubes Negative [ppMaxSubdiv]
 The set N: Probes for which the verification of the property was negative.
ppCubes Good [ppMaxSubdiv]
 The set G: Good probes, that is, probes for which the property was verified successfully.
ppCubes Test [ppMaxSubdiv]
 The set T: Probes which have to be sent for testing.
ppCubes CurProbes [ppMaxSubdiv]
 Part of the set C2: Currently processed probes.
ppCubes Failed [ppMaxSubdiv]
 The set F: Boxes for which the verification failed.
ppCubes Successful [ppMaxSubdiv]
 The set A: Boxes which are successfully verified to satisfy the given property and thus are contained in the set A.
ppCubes Waiting [ppMaxSubdiv]
 The set W: Boxes waiting for verification.
ppCubes CurBoxes [ppMaxSubdiv]
 Part of the set C: Currently processed boxes.
double paramLeft [dim]
 The left (minimal) vertices of the parameter cube.
double paramRight [dim]
 The right (maximal) vertices of the parameter cube.
int inilevel
 The level of subdivisions in the parameter space at which the actual computations begin.
int maxlevel
 The maximal allowed level of subdivision in the parameter space.
mwIniProbes< dim, coord > iniProbes
 An iterator of initial probes.
ppCubes iniProcessed
 A set of previously processed initial probes (used only if continuing the computations).
std::ofstream f
 A file to append the results to.
bool flushfile
 Should the results file be flushed after every write?
int current
 The counter of data packs prepared by a coordinator.
multitable< ppPacksent
 The data packs sent for processing.
int sentlen
 The number of data packs sent for processing.
int countNegative
 The number of processed probes with negative result.
int countGood
 The number of processed probes which turn out to be good.
int countFailed
 The number of processed boxes for which the verification failed.
int countSuccessful
 The number of processed boxes for which the verification was successful.

Static Private Attributes

static const int ppMaxSubdiv = 8 * sizeof (coord) - 2
 The maximal feasible subdivision level.
static const int ppMaxDim = ppCube::MaxDim
 The maximal dimension of cubes.

Detailed Description

template<int dim, class coord>
class chomp::multiwork::mwSubCoordinator< dim, coord >

This class defines a coordinator for the multi-work subdivision framework.

Definition at line 555 of file mwsubdiv.h.


Member Typedef Documentation

template<int dim, class coord>
typedef tCubeFix<dim,coord> chomp::multiwork::mwSubCoordinator< dim, coord >::ppCube [private]

The maximal feasible subdivision level.

The type of a cube of parameters.

Definition at line 564 of file mwsubdiv.h.

template<int dim, class coord>
typedef hashedset<ppCube> chomp::multiwork::mwSubCoordinator< dim, coord >::ppCubes [private]

The type of a set of cubes in the parameter space.

Definition at line 570 of file mwsubdiv.h.

template<int dim, class coord>
typedef mwSubDataPack<dim,coord> chomp::multiwork::mwSubCoordinator< dim, coord >::ppPack [private]

The type of a sent data pack kept in an internal array.

Definition at line 576 of file mwsubdiv.h.

template<int dim, class coord>
typedef tRectangle<coord> chomp::multiwork::mwSubCoordinator< dim, coord >::ppRect [private]

The kind of rectangle used to iterate ranges of cubes.

Definition at line 573 of file mwsubdiv.h.


Constructor & Destructor Documentation

template<int dim, class coord >
chomp::multiwork::mwSubCoordinator< dim, coord >::mwSubCoordinator (  )  [inline]

The constructor of an uninitialized coordinator.

Definition at line 751 of file mwsubdiv.h.

{
        return;
} /* mwSubCoordinator<dim,coord>::mwSubCoordinator */

template<int dim, class coord >
chomp::multiwork::mwSubCoordinator< dim, coord >::mwSubCoordinator ( const char *  filename,
int  _inilevel,
int  _maxlevel,
bool  _flushfile,
const double *  _paramLeft,
const double *  _paramRight 
)

The complete constructor of a coordinator object.

Definition at line 757 of file mwsubdiv.h.

References chomp::homology::currenttime(), chomp::multiwork::mwSubCoordinator< dim, coord >::f, chomp::multiwork::mwSubCoordinator< dim, coord >::flushfile, chomp::multiwork::mwSubCoordinator< dim, coord >::inilevel, chomp::multiwork::mwSubCoordinator< dim, coord >::maxlevel, chomp::multiwork::mwSubCoordinator< dim, coord >::paramLeft, chomp::multiwork::mwSubCoordinator< dim, coord >::paramRight, chomp::multiwork::mwSubCoordinator< dim, coord >::ppMaxSubdiv, chomp::multiwork::mwSubCoordinator< dim, coord >::ReadResults(), and chomp::homology::sout.

                                                            :
        inilevel ((_inilevel < 2) ? 2 : _inilevel),
        maxlevel ((_maxlevel <= inilevel) ? (inilevel + 1) : _maxlevel),
        iniProbes (inilevel),
        flushfile (_flushfile),
        current (0), sentlen (0),
        countNegative (0), countGood (0),
        countFailed (0), countSuccessful (0)
{
        // display a warning if no file name is provided
        if (!filename || !*filename)
                sout << "WARNING: No results file name given. "
                        "Computation results will not be saved.\n";

        // initialize the subdivision levels
        if (maxlevel > ppMaxSubdiv)
        {
                sout << "WARNING: Max subdivision level decreased from " <<
                        maxlevel << " to " << ppMaxSubdiv << ".\n";
                maxlevel = ppMaxSubdiv;
                if (inilevel >= maxlevel)
                        inilevel = maxlevel - 1;
        }

        // read the previously computed results of the computations
        if (filename && *filename)
        {
                std::ifstream in (filename);
                if (!in)
                        sout << "Note: Could not open the results file. "
                        "Any previous results will be ignored.\n";
                else
                {
                        this -> ReadResults (in);
                        in. close ();
                }
        }

        // open the results file for appending
        if (filename && *filename)
        {
                f. open (filename, std::ios::out | std::ios::app);
                f << "; Started on " << currenttime ();
                if (flushfile)
                        f << std::flush;
        }

        // copy the left and right ends of the intervals
        for (int i = 0; i < dim; ++ i)
        {
                paramLeft [i] = _paramLeft [i];
                paramRight [i] = _paramRight [i];
        }

        return;
} /* mwSubCoordinator<dim,coord>::mwSubCoordinator */

template<int dim, class coord >
chomp::multiwork::mwSubCoordinator< dim, coord >::~mwSubCoordinator (  )  [inline]

The destructor.

Definition at line 817 of file mwsubdiv.h.

References chomp::multiwork::mwSubCoordinator< dim, coord >::countFailed, chomp::multiwork::mwSubCoordinator< dim, coord >::countGood, chomp::multiwork::mwSubCoordinator< dim, coord >::countNegative, chomp::multiwork::mwSubCoordinator< dim, coord >::countSuccessful, chomp::homology::currenttime(), and chomp::multiwork::mwSubCoordinator< dim, coord >::f.

{
        f << "; A total of " << (countNegative + countGood) <<
                " probes and " << (countFailed + countSuccessful) <<
                " boxes have been processed.\n";
        f << "; The verification was negative for " << countNegative <<
                " probes, and " << countGood << " probes were good.\n";
        f << "; The verification failed for " << countFailed <<
                " boxes, and was successful for " << countSuccessful <<
                " boxes.\n";
        f << "; Finished on " << currenttime ();
        f << "; ---------------------------------------------------\n";
        f. close ();
        return;
} /* mwSubCoordinator<dim,coord>::~mwSubCoordinator */


Member Function Documentation

template<int dim, class coord >
int chomp::multiwork::mwSubCoordinator< dim, coord >::Accept ( mwData data  )  [private, virtual]

A function for accepting results by a coordinator.

Reimplemented from chomp::multiwork::mwCoordinator.

Definition at line 1287 of file mwsubdiv.h.

References chomp::multiwork::mwSubCoordinator< dim, coord >::countFailed, chomp::multiwork::mwSubCoordinator< dim, coord >::countGood, chomp::multiwork::mwSubCoordinator< dim, coord >::countNegative, chomp::multiwork::mwSubCoordinator< dim, coord >::countSuccessful, chomp::multiwork::mwSubCoordinator< dim, coord >::CurBoxes, chomp::multiwork::mwSubCoordinator< dim, coord >::CurProbes, chomp::multiwork::mwSubCoordinator< dim, coord >::f, chomp::multiwork::mwSubCoordinator< dim, coord >::FailedBox(), chomp::multiwork::mwSubCoordinator< dim, coord >::flushfile, chomp::multiwork::mwSubCoordinator< dim, coord >::GoodProbe(), chomp::multiwork::mwSubCoordinator< dim, coord >::NegativeProbe(), chomp::multiwork::mwSubCoordinator< dim, coord >::sentlen, chomp::homology::sout, chomp::multiwork::mwSubCoordinator< dim, coord >::SuccessfulBox(), chomp::multiwork::mwSubCoordinator< dim, coord >::Test, and chomp::multiwork::mwSubCoordinator< dim, coord >::Waiting.

{
        // decode the data pack number
        int n = 0;
        data >> n;

        // decode the result
        int result = 0;
        data >> result;

        // say what has been received
        sout << "* " << n << " " << result << ".\n";

        // find this data among the data packs that were sent for processing
        int pos = 0;
        while ((pos < sentlen) && (sent [pos]. num != n))
                ++ pos;
        if (pos >= sentlen)
        {
                sout << "ERROR: Wrong data pack number received "
                        "from a worker.\n";
                return mwError;
        }
        const ppPack &pack = sent [pos];

        // save the data to the output file
        f << (pack. full ? "* " : "@ ") << n << " " << result <<
                " " << pack. level << " " << pack. q << ".\n";
        if (flushfile)
                f << std::flush;
        
        // extract the data from the data pack
        const ppCube &q = pack. q;
        int level = pack. level;
        bool full = pack. full;

        // remove the cube from appropriate sets and process it
        if (full)
        {
                CurBoxes [level]. remove (q);
                Waiting [level]. remove (q);
                if (result)
                {
                        ++ countSuccessful;
                        SuccessfulBox (q, level);
                }
                else
                {
                        ++ countFailed;
                        FailedBox (q, level);
                }
        }
        else
        {
                CurProbes [level]. remove (q);
                Test [level]. remove (q);
                if (result)
                {
                        ++ countGood;
                        GoodProbe (q, level);
                }
                else
                {
                        ++ countNegative;
                        NegativeProbe (q, level);
                }
        }

        // remove the data pack from the table containing the data packs
        -- sentlen;
        if (pos != sentlen)
                sent [pos] = sent [sentlen];

        return mwOk;
} /* mwSubCoordinator<dim,coord>::Accept */

template<int dim, class coord >
int chomp::multiwork::mwSubCoordinator< dim, coord >::Contained ( const typename mwSubCoordinator< dim, coord >::ppCube q,
int  level,
const typename mwSubCoordinator< dim, coord >::ppCubes  tab[],
int  minlevel 
) const [private]

Verifies if the given box is contained in a box at any level greater than or equal to the given minimum in the given family of boxes.

Returns the level of a box which is found or 0 if none.

Definition at line 1056 of file mwsubdiv.h.

Referenced by chomp::multiwork::mwSubCoordinator< dim, coord >::GoodProbe(), and chomp::multiwork::mwSubCoordinator< dim, coord >::SuccessfulBox().

{
        // verify if the box itself is contained in any set of boxes
        if (tab [level]. check (q))
                return level;

        // subdivide the box and verify at a higher level
        if (minlevel < inilevel)
                minlevel = inilevel;
        ppCube box = q;
        while (-- level > minlevel)
        {
                box = DownLevel (box);
                if (tab [level]. check (box))
                        return level;
        }

        return 0;
} /* mwSubCoordinator::Contained */

template<int dim, class coord >
mwSubCoordinator< dim, coord >::ppCube chomp::multiwork::mwSubCoordinator< dim, coord >::DownLevel ( const typename mwSubCoordinator< dim, coord >::ppCube q  )  [static, private]

Returns a box with respect to a higher level grid which contains the given box, that is, divides all the coordinates by 2.

Definition at line 1045 of file mwsubdiv.h.

{
        coord c [dim];
        q. coord (c);
        for (int i = 0; i < dim; ++ i)
                c [i] >>= 1;
        return ppCube (c, dim);
} /* mwSubCoordinator::DownLevel */

template<int dim, class coord >
void chomp::multiwork::mwSubCoordinator< dim, coord >::FailedBox ( const ppCube q,
int  level 
) [private]

A function for acquiring a box for which the verification failed.

Definition at line 1151 of file mwsubdiv.h.

References chomp::multiwork::mwSubCoordinator< dim, coord >::Failed, chomp::multiwork::mwSubCoordinator< dim, coord >::Good, chomp::multiwork::mwSubCoordinator< dim, coord >::Negative, chomp::homology::sbug, chomp::multiwork::mwSubCoordinator< dim, coord >::Successful, chomp::multiwork::mwSubCoordinator< dim, coord >::Test, chomp::multiwork::mwSubCoordinator< dim, coord >::UpLevel(), and chomp::multiwork::mwSubCoordinator< dim, coord >::Waiting.

Referenced by chomp::multiwork::mwSubCoordinator< dim, coord >::Accept(), chomp::multiwork::mwSubCoordinator< dim, coord >::NegativeProbe(), and chomp::multiwork::mwSubCoordinator< dim, coord >::ReadResults().

{
        // add the box to the list of boxes which failed
        Failed [level]. add (q);
        sbug << "@ FailedBox [" << level << "]: " << q << "\n";

        // if no further subdivisions are to be considered then quit here
        if (level + 1 == maxlevel)
                return;

        // consider all the corners of the box
        mwCorners<dim,coord> corners (q);
        while (corners. available ())
        {
                // take the next corner of the box
                ppCube c = corners. get ();

                // if this is a negative probe then skip it
                if (Negative [level]. check (c))
                        continue;

                // if this probe has not yet been checked
                // then add it to the list of probes to test
                if (!Good [level]. check (c))
                {
                        Test [level]. add (c);
                        sbug << "+ Test [" << level << "]: " << c << "\n";
                        continue;
                }

                // add a twice smaller box located at the given corner
                // to the list of boxes which wait for being verified,
                // unless the result for this box is already known
                ppCube box = UpLevel (q, c);
                if (!Successful [level + 1]. check (box) &&
                        !Failed [level + 1]. check (box))
                {
                        Waiting [level + 1]. add (box);
                        sbug << "+ Waiting [" << (level + 1) << "]: " <<
                                box << "\n";
                }

                // mark the probe as good at the higher subdivision level
                ppCube probe = UpLevel (c);
                Good [level + 1]. add (probe);
                sbug << "+ Good [" << (level + 1) << "]: " << probe << "\n";
        }

        return;
} /* mwSubCoordinator::FailedBox */

template<int dim, class coord >
bool chomp::multiwork::mwSubCoordinator< dim, coord >::FindMinCube ( const typename mwSubCoordinator< dim, coord >::ppCubes  tab[],
const typename mwSubCoordinator< dim, coord >::ppCubes  sent[],
int  minlevel,
int  maxlevel,
int &  level,
typename mwSubCoordinator< dim, coord >::ppCube q 
) [inline, private]

Finds a cube at the lowest level (>= min, < max) of the given set of cubes that was not sent, yet.

Modifies 'level' and 'q'. Returns true if found, false if not found.

Definition at line 837 of file mwsubdiv.h.

Referenced by chomp::multiwork::mwSubCoordinator< dim, coord >::Prepare().

{
        for (int l = minlevel; l < maxlevel; ++ l)
        {
                const ppCubes &theSet = tab [l];
                const ppCubes &sentSet = sent [l];
                int number = theSet. size ();
                for (int i = number - 1; i >= 0; -- i)
                {
                        const ppCube &c = theSet [i];
                        if (!sentSet. check (c))
                        {
                                level = l;
                                q = c;
                                return true;
                        }
                }
        }
        return false;
} /* mwSubCoordinator::FindMinCube */

template<int dim, class coord >
void chomp::multiwork::mwSubCoordinator< dim, coord >::GoodProbe ( const ppCube q,
int  level 
) [private]

A function for acquiring a good probe.

Definition at line 1109 of file mwsubdiv.h.

References chomp::multiwork::mwSubCoordinator< dim, coord >::Contained(), chomp::multiwork::mwSubCoordinator< dim, coord >::Good, chomp::homology::sbug, chomp::multiwork::mwSubCoordinator< dim, coord >::Successful, chomp::multiwork::mwSubCoordinator< dim, coord >::UpLevel(), and chomp::multiwork::mwSubCoordinator< dim, coord >::Waiting.

Referenced by chomp::multiwork::mwSubCoordinator< dim, coord >::Accept(), and chomp::multiwork::mwSubCoordinator< dim, coord >::ReadResults().

{
        // if it is already known that this probe is good then skip it
        if (Good [level]. check (q))
        {
                sbug << "@ GoodKnown [" << level << "]: " << q << "\n";
                return;
        }

        // add the probe to the set of good probes at its level
        Good [level]. add (q);
        sbug << "@ GoodProbe [" << level << "]: " << q << "\n";

        // if the next level is beyond the scope then quit here
        if (level + 1 == maxlevel)
                return;

        // transfer the probe to the next level and remember that it is good
        ppCube probe = UpLevel (q);
        Good [level + 1]. add (probe);
        sbug << "+ GoodProbe [" << (level + 1) << "]: " << probe << "\n";

        // consider all the boxes which contain this probe
        mwBoxes<dim,coord> boxes (probe);
        while (boxes. available ())
        {
                // if the box is not contained in any larger successful box
                // then add it to the waiting list
                ppCube box = boxes. get ();
                if (!Contained (box, level + 1, Successful, 0))
                {
                        
                        Waiting [level + 1]. add (box);
                        sbug << "+ Waiting [" << (level + 1) << "]: " <<
                                box << "\n";
                }
        }

        return;
} /* mwSubCoordinator::GoodProbe */

template<int dim, class coord >
void chomp::multiwork::mwSubCoordinator< dim, coord >::NegativeProbe ( const ppCube q,
int  level 
) [private]

A function for acquiring a negative probe.

Definition at line 1079 of file mwsubdiv.h.

References chomp::multiwork::mwSubCoordinator< dim, coord >::CurBoxes, chomp::multiwork::mwSubCoordinator< dim, coord >::FailedBox(), chomp::multiwork::mwSubCoordinator< dim, coord >::Negative, chomp::homology::sbug, and chomp::multiwork::mwSubCoordinator< dim, coord >::Waiting.

Referenced by chomp::multiwork::mwSubCoordinator< dim, coord >::Accept(), and chomp::multiwork::mwSubCoordinator< dim, coord >::ReadResults().

{
        // add the probe to the set of negative probes
        Negative [level]. add (q);
        sbug << "@ NegProbe [" << level << "]: " << q << "\n";

        // boxes around this probe automatically fail, so remove them
        // from the queue and interpret them as failed boxes
        mwBoxes<dim,coord> boxes (q);
        while (boxes. available ())
        {
                // take a box which has this probe in its corner
                ppCube box = boxes. get ();

                // if it is waiting for processing but was not sent yet
                // then pretend it has just returned as a failed box
                if (Waiting [level]. check (box) &&
                        !CurBoxes [level]. check (box))
                {
                        sbug << "# FailedBox [" << level << "]: " <<
                                box << "\n";
                        Waiting [level]. remove (box);
                        FailedBox (box, level);
                }
        }

        return;
} /* mwSubCoordinator::NegativeProbe */

template<int dim, class coord >
int chomp::multiwork::mwSubCoordinator< dim, coord >::Prepare ( mwData data  )  [private, virtual]

A function for preparing data by a coordinator.

Reimplemented from chomp::multiwork::mwCoordinator.

Definition at line 862 of file mwsubdiv.h.

References chomp::multiwork::mwSubCoordinator< dim, coord >::CurBoxes, chomp::multiwork::mwSubCoordinator< dim, coord >::CurProbes, chomp::multiwork::mwSubCoordinator< dim, coord >::current, chomp::multiwork::mwSubCoordinator< dim, coord >::f, chomp::multiwork::mwSubCoordinator< dim, coord >::FindMinCube(), chomp::multiwork::mwSubCoordinator< dim, coord >::flushfile, chomp::multiwork::mwSubCoordinator< dim, coord >::inilevel, chomp::multiwork::mwSubCoordinator< dim, coord >::iniProbes, chomp::multiwork::mwSubCoordinator< dim, coord >::iniProcessed, chomp::multiwork::mwSubdivPoint(), chomp::multiwork::mwSubCoordinator< dim, coord >::paramLeft, chomp::multiwork::mwSubCoordinator< dim, coord >::paramRight, chomp::multiwork::mwSubCoordinator< dim, coord >::ppMaxDim, chomp::multiwork::mwSubCoordinator< dim, coord >::sentlen, chomp::homology::sout, chomp::multiwork::mwSubCoordinator< dim, coord >::Test, and chomp::multiwork::mwSubCoordinator< dim, coord >::Waiting.

{
        // prepare a data pack to send
        ppPack &pack = sent [sentlen];

        // if there is any initial probe that has not yet been processed
        // then take this probe
        bool iniProbe = false;
        while (iniProbes. available ())
        {
                pack = ppPack (current, iniProbes. get (), inilevel, false);
                if (iniProcessed. check (pack. q))
                {
                        iniProcessed. remove (pack. q);
                        continue;
                }
                else
                {
                        iniProbe = true;
                        break;
                }
        }

        // otherwise send a probe or a box which is waiting to be verified
        if (!iniProbe)
        {
                // find a probe for testing at the lowest level available
                int levelT = 0;
                ppCube cubeT;
                bool foundT = this -> FindMinCube (Test, CurProbes,
                        inilevel, maxlevel, levelT, cubeT);

                // find a box that is waiting at the lowest level available
                int levelW = 0;
                ppCube cubeW;
                bool foundW = this -> FindMinCube (Waiting, CurBoxes,
                        inilevel, maxlevel, levelW, cubeW);

                // if no cube for processing can be found, then interrupt
                if (!foundT && !foundW)
                        return mwNoData;

                // send the probe found if this is the right thing to do
                if (foundT && (!foundW || (levelT <= levelW)))
                {
                        pack = ppPack (current, cubeT, levelT, false);
                        CurProbes [levelT]. add (cubeT);
                }
                // otherwise send the box found
                else
                {
                        pack = ppPack (current, cubeW, levelW, true);
                        CurBoxes [levelW]. add (cubeW);
                }
        }

        // prepare the intervals of parameters corresponding to the cube
        coord c [ppMaxDim];
        pack. q. coord (c);
        int fullSize = 1 << pack. level;
        double left [ppMaxDim];
        double right [ppMaxDim];
        for (int i = 0; i < dim; ++ i)
        {
                // prepare the probe or the left corner of the box
                left [i] = mwSubdivPoint (paramLeft [i], paramRight [i],
                        c [i], fullSize);

                // if this is a full box then compute the right corner, too
                if (pack. full)
                {
                        // prepare the right corner of the box
                        right [i] =  mwSubdivPoint (paramLeft [i],
                                paramRight [i], c [i] + 1, fullSize);

                        // if the resolution of the representable numbers
                        // has been reached then set this level to be
                        // the strict upper bound for the subdivision level
                        if (left [i] == right [i])
                        {
                                // leave a note of this situation in the file
                                f << "; The resolution of representable "
                                        "numbers exceeded.\n; Decreasing "
                                        "max level from " << maxlevel <<
                                        " to " << pack. level << ".\n";
                                if (flushfile)
                                        f << std::flush;

                                // notify the user about this situation
                                sout << "WARNING: The resolution of "
                                        "representable numbers exceeded.\n"
                                        "Decreasing max level from " <<
                                        maxlevel << " to " << pack. level <<
                                        ".\n";

                                // decrease the max level limit
                                maxlevel = pack. level;
                                return mwNoData;
                        }
                }
        }

        // write th information on the prepared cube to the results file
        f << "+ " << pack. num;
        for (int i = 0; i < dim; ++ i)
        {
                f << (i ? "x[" : " [") << left [i];
                if (pack. full)
                        f << "," << right [i];
                f << "]";
        }
        f << ".\n";
        if (flushfile)
                f << std::flush;

        // send the data pack number
        data << pack. num;
        
        // send the subdivision level
        data << pack. level;

        // send the information on whether this is a full box or a probe
        data << pack. full;

        // send the intervals (left and right ends where applicable)
        for (int i = 0; i < dim; ++ i)
        {
                data << left [i];
                if (pack. full)
                        data << right [i];
        }

        // append the data end marker for extra verification
        const int dataEndMarker = 13;
        data << dataEndMarker;

        // show a message on which data pack has been prepared
        sout << "+ " << pack. num << ".\n";

        // increase the counters
        ++ current;
        ++ sentlen;

        return mwOk;
} /* mwSubCoordinator<dim,coord>::Prepare */

template<int dim, class coord >
int chomp::multiwork::mwSubCoordinator< dim, coord >::ReadResults ( std::istream &  in  )  [private]

A procedure for reading the previously computed results.

Definition at line 1379 of file mwsubdiv.h.

References chomp::multiwork::mwSubCoordinator< dim, coord >::FailedBox(), chomp::multiwork::mwSubCoordinator< dim, coord >::GoodProbe(), chomp::homology::ignorecomments(), chomp::homology::ignoreline(), chomp::multiwork::mwSubCoordinator< dim, coord >::inilevel, chomp::multiwork::mwSubCoordinator< dim, coord >::iniProcessed, chomp::multiwork::mwSubCoordinator< dim, coord >::NegativeProbe(), chomp::multiwork::mwSubCoordinator< dim, coord >::SuccessfulBox(), chomp::multiwork::mwSubCoordinator< dim, coord >::Test, and chomp::multiwork::mwSubCoordinator< dim, coord >::Waiting.

Referenced by chomp::multiwork::mwSubCoordinator< dim, coord >::mwSubCoordinator().

{
        ignorecomments (in);
        while (!in. eof ())
        {
                // read the first char and interprete the line
                int ch = in. get ();

                // ignore the line if it contains no useful information
                if ((ch != '*') && (ch != '@'))
                {
                        ignoreline (in);
                        ignorecomments (in);
                        continue;
                }
        
                // read the data number if relevant
                if ((ch == '*') || (ch == '@'))
                {
                        int n = -1;
                        in >> n;
                        if (n < 0)
                                break;
                }

                // read the result if any
                int result = -1;
                if ((ch == '*') || (ch == '@'))
                {
                        in >> result;
                        if (result < 0)
                                break;
                }

                // read the subdivision level of the cube
                int level = -1;
                in >> level;
                if (level < 0)
                        break;

                // read the cube itself
                ppCube q;
                in >> q;

                // make sure that there is the dot which ends the line
                if (in. peek () != '.')
                        break;

                // ignore the remaining part of the line
                ignoreline (in);
                ignorecomments (in);

                // process the data as necessary
                if (ch == '*')
                {
                        Waiting [level]. remove (q);
                        if (result)
                                SuccessfulBox (q, level);
                        else
                                FailedBox (q, level);
                }
                else if (ch == '@')
                {
                        if (level == inilevel)
                                iniProcessed. add (q);
                        else
                                Test [level]. remove (q);
                        if (result)
                                GoodProbe (q, level);
                        else
                                NegativeProbe (q, level);
                }
        }

        return 0;
} /* mwSubCoordinator<dim,coord>::ReadResults */

template<int dim, class coord >
int chomp::multiwork::mwSubCoordinator< dim, coord >::Reject ( mwData data  )  [private, virtual]

A function for taking rejected data by a coordinator.

Reimplemented from chomp::multiwork::mwCoordinator.

Definition at line 1364 of file mwsubdiv.h.

References chomp::homology::sout.

{
        // decode the number
        int n = 0;
        data >> n;

        // say that data has been rejected
        sout << "!!! Data no. " << n << " rejected.\n";

        return mwError;
} /* mwSubCoordinator<dim,coord>::Reject */

template<int dim, class coord >
void chomp::multiwork::mwSubCoordinator< dim, coord >::SuccessfulBox ( const ppCube q,
int  level 
) [private]

A function for acquiring a successful box.

Definition at line 1203 of file mwsubdiv.h.

References chomp::multiwork::mwSubCoordinator< dim, coord >::Contained(), chomp::multiwork::mwSubCoordinator< dim, coord >::Good, chomp::homology::sbug, chomp::multiwork::mwSubCoordinator< dim, coord >::Successful, chomp::multiwork::mwSubCoordinator< dim, coord >::Test, chomp::multiwork::mwSubCoordinator< dim, coord >::UpLevel(), and chomp::multiwork::mwSubCoordinator< dim, coord >::Waiting.

Referenced by chomp::multiwork::mwSubCoordinator< dim, coord >::Accept(), and chomp::multiwork::mwSubCoordinator< dim, coord >::ReadResults().

{
        // if the box has already been added then skip it
        if (Successful [level]. check (q))
        {
                sbug << "@ SuccessKnown [" << level << "]: " << q << "\n";
                return;
        }

        // if this box is already contained in a larger successful box
        // then ignore it
        if (Contained (q, level, Successful, 0))
        {
                sbug << "@ SuccessSubset [" << level << "]: " << q << "\n";
                return;
        }

        // add the box to the set of successful boxes which form the set A
        Successful [level]. add (q);
        sbug << "@ SuccessBox [" << level << "]: " << q << "\n";

        // consider all the vertices of this box
        mwCorners<dim,coord> corners (q);
        while (corners. available ())
        {
                // take the next corner of the box
                ppCube c = corners. get ();

                // remove the corner probe from a list of probes to test
                if (Test [level]. check (c))
                {
                        Test [level]. remove (c);
                        sbug << "- Test [" << level << "]: " << c << "\n";
                }

                // remove the corner box from a list of boxes to test
                ppCube cornerBox = UpLevel (q, c);
                if (Waiting [level + 1]. check (cornerBox))
                {
                        Waiting [level + 1]. remove (cornerBox);
                        sbug << "- Waiting [" << (level + 1) << "]: " <<
                                cornerBox << "\n";
                        // note: there might be some boxes contained in q
                        // waiting at deeper levels, but determining them
                        // might be quite inefficient,
                        // so they are not cleaned in this implementation
                        // of the algorithm
                }

                // if the probe is already known to be good then skip it
                if (Good [level]. check (c))
                        continue;

                // add the probe to the list of good ones
                Good [level]. add (c);
                sbug << "+ Good [" << level << "]: " << c << "\n";

                // propagate the probe one level deeper and mark it as good
                ppCube probe = UpLevel (c);
                Good [level + 1]. add (probe);
                sbug << "+ Good [" << (level + 1) << "]: " << probe << "\n";

                // consider all the boxes which contain this probe
                mwBoxes<dim,coord> boxes (probe);
                while (boxes. available ())
                {
                        // take the next box
                        ppCube box = boxes. get ();

                        // if this box is not contained in any successful
                        // larger box then add it to the waiting list
                        if (!Contained (box, level + 1, Successful, 0))
                        {
                                Waiting [level + 1]. add (box);
                                sbug << "+ Waiting [" << (level + 1) <<
                                        "]: " << box << "\n";
                        }
                }
        }

        return;
} /* mwSubCoordinator::SuccessfulBox */

template<int dim, class coord >
mwSubCoordinator< dim, coord >::ppCube chomp::multiwork::mwSubCoordinator< dim, coord >::UpLevel ( const typename mwSubCoordinator< dim, coord >::ppCube box,
const typename mwSubCoordinator< dim, coord >::ppCube corner 
) [static, private]

Returns a box with respect to a higher level grid which is contained in the given box and contains the given corner.

Definition at line 1025 of file mwsubdiv.h.

{
        coord cBox [dim];
        box. coord (cBox);
        coord cCorner [dim];
        corner. coord (cCorner);
        for (int i = 0; i < dim; ++ i)
        {
                if (cBox [i] == cCorner [i])
                        cBox [i] <<= 1;
                else
                        cBox [i] = (cBox [i] << 1) + 1;
        }
        return ppCube (cBox, dim);
} /* mwSubCoordinator::UpLevel */

template<int dim, class coord >
mwSubCoordinator< dim, coord >::ppCube chomp::multiwork::mwSubCoordinator< dim, coord >::UpLevel ( const typename mwSubCoordinator< dim, coord >::ppCube q  )  [static, private]

Returns a probe with respect to a higher level grid, that is, multiplies all the coordinates by 2.

Definition at line 1013 of file mwsubdiv.h.

Referenced by chomp::multiwork::mwSubCoordinator< dim, coord >::FailedBox(), chomp::multiwork::mwSubCoordinator< dim, coord >::GoodProbe(), and chomp::multiwork::mwSubCoordinator< dim, coord >::SuccessfulBox().

{
        coord c [dim];
        q. coord (c);
        for (int i = 0; i < dim; ++ i)
                c [i] <<= 1;
        return ppCube (c, dim);
} /* mwSubCoordinator::UpLevel */


Member Data Documentation

template<int dim, class coord>
int chomp::multiwork::mwSubCoordinator< dim, coord >::countFailed [private]

The number of processed boxes for which the verification failed.

Definition at line 735 of file mwsubdiv.h.

Referenced by chomp::multiwork::mwSubCoordinator< dim, coord >::Accept(), and chomp::multiwork::mwSubCoordinator< dim, coord >::~mwSubCoordinator().

template<int dim, class coord>
int chomp::multiwork::mwSubCoordinator< dim, coord >::countGood [private]

The number of processed probes which turn out to be good.

Definition at line 732 of file mwsubdiv.h.

Referenced by chomp::multiwork::mwSubCoordinator< dim, coord >::Accept(), and chomp::multiwork::mwSubCoordinator< dim, coord >::~mwSubCoordinator().

template<int dim, class coord>
int chomp::multiwork::mwSubCoordinator< dim, coord >::countNegative [private]

The number of processed probes with negative result.

Definition at line 729 of file mwsubdiv.h.

Referenced by chomp::multiwork::mwSubCoordinator< dim, coord >::Accept(), and chomp::multiwork::mwSubCoordinator< dim, coord >::~mwSubCoordinator().

template<int dim, class coord>
int chomp::multiwork::mwSubCoordinator< dim, coord >::countSuccessful [private]

The number of processed boxes for which the verification was successful.

Definition at line 739 of file mwsubdiv.h.

Referenced by chomp::multiwork::mwSubCoordinator< dim, coord >::Accept(), and chomp::multiwork::mwSubCoordinator< dim, coord >::~mwSubCoordinator().

template<int dim, class coord>
ppCubes chomp::multiwork::mwSubCoordinator< dim, coord >::CurProbes[ppMaxSubdiv] [private]

Part of the set C2: Currently processed probes.

Definition at line 616 of file mwsubdiv.h.

Referenced by chomp::multiwork::mwSubCoordinator< dim, coord >::Accept(), and chomp::multiwork::mwSubCoordinator< dim, coord >::Prepare().

template<int dim, class coord>
int chomp::multiwork::mwSubCoordinator< dim, coord >::current [private]

The counter of data packs prepared by a coordinator.

Definition at line 718 of file mwsubdiv.h.

Referenced by chomp::multiwork::mwSubCoordinator< dim, coord >::Prepare().

template<int dim, class coord>
ppCubes chomp::multiwork::mwSubCoordinator< dim, coord >::Failed[ppMaxSubdiv] [private]

The set F: Boxes for which the verification failed.

Definition at line 619 of file mwsubdiv.h.

Referenced by chomp::multiwork::mwSubCoordinator< dim, coord >::FailedBox().

template<int dim, class coord>
bool chomp::multiwork::mwSubCoordinator< dim, coord >::flushfile [private]
template<int dim, class coord>
ppCubes chomp::multiwork::mwSubCoordinator< dim, coord >::Good[ppMaxSubdiv] [private]

The set G: Good probes, that is, probes for which the property was verified successfully.

Definition at line 610 of file mwsubdiv.h.

Referenced by chomp::multiwork::mwSubCoordinator< dim, coord >::FailedBox(), chomp::multiwork::mwSubCoordinator< dim, coord >::GoodProbe(), and chomp::multiwork::mwSubCoordinator< dim, coord >::SuccessfulBox().

template<int dim, class coord>
int chomp::multiwork::mwSubCoordinator< dim, coord >::inilevel [private]

The level of subdivisions in the parameter space at which the actual computations begin.

Definition at line 692 of file mwsubdiv.h.

Referenced by chomp::multiwork::mwSubCoordinator< dim, coord >::mwSubCoordinator(), chomp::multiwork::mwSubCoordinator< dim, coord >::Prepare(), and chomp::multiwork::mwSubCoordinator< dim, coord >::ReadResults().

template<int dim, class coord>
mwIniProbes<dim,coord> chomp::multiwork::mwSubCoordinator< dim, coord >::iniProbes [private]

An iterator of initial probes.

Definition at line 698 of file mwsubdiv.h.

Referenced by chomp::multiwork::mwSubCoordinator< dim, coord >::Prepare().

template<int dim, class coord>
ppCubes chomp::multiwork::mwSubCoordinator< dim, coord >::iniProcessed [private]

A set of previously processed initial probes (used only if continuing the computations).

Definition at line 702 of file mwsubdiv.h.

Referenced by chomp::multiwork::mwSubCoordinator< dim, coord >::Prepare(), and chomp::multiwork::mwSubCoordinator< dim, coord >::ReadResults().

template<int dim, class coord>
int chomp::multiwork::mwSubCoordinator< dim, coord >::maxlevel [private]

The maximal allowed level of subdivision in the parameter space.

Definition at line 695 of file mwsubdiv.h.

Referenced by chomp::multiwork::mwSubCoordinator< dim, coord >::mwSubCoordinator().

template<int dim, class coord>
ppCubes chomp::multiwork::mwSubCoordinator< dim, coord >::Negative[ppMaxSubdiv] [private]

The set N: Probes for which the verification of the property was negative.

Definition at line 606 of file mwsubdiv.h.

Referenced by chomp::multiwork::mwSubCoordinator< dim, coord >::FailedBox(), and chomp::multiwork::mwSubCoordinator< dim, coord >::NegativeProbe().

template<int dim, class coord>
double chomp::multiwork::mwSubCoordinator< dim, coord >::paramLeft[dim] [private]

The left (minimal) vertices of the parameter cube.

Definition at line 685 of file mwsubdiv.h.

Referenced by chomp::multiwork::mwSubCoordinator< dim, coord >::mwSubCoordinator(), and chomp::multiwork::mwSubCoordinator< dim, coord >::Prepare().

template<int dim, class coord>
double chomp::multiwork::mwSubCoordinator< dim, coord >::paramRight[dim] [private]

The right (maximal) vertices of the parameter cube.

Definition at line 688 of file mwsubdiv.h.

Referenced by chomp::multiwork::mwSubCoordinator< dim, coord >::mwSubCoordinator(), and chomp::multiwork::mwSubCoordinator< dim, coord >::Prepare().

template<int dim, class coord>
const int chomp::multiwork::mwSubCoordinator< dim, coord >::ppMaxDim = ppCube::MaxDim [static, private]

The maximal dimension of cubes.

Definition at line 567 of file mwsubdiv.h.

Referenced by chomp::multiwork::mwSubCoordinator< dim, coord >::Prepare().

template<int dim, class coord>
const int chomp::multiwork::mwSubCoordinator< dim, coord >::ppMaxSubdiv = 8 * sizeof (coord) - 2 [static, private]

The maximal feasible subdivision level.

Definition at line 558 of file mwsubdiv.h.

Referenced by chomp::multiwork::mwSubCoordinator< dim, coord >::mwSubCoordinator().

template<int dim, class coord>
multitable<ppPack> chomp::multiwork::mwSubCoordinator< dim, coord >::sent [private]

The data packs sent for processing.

Definition at line 721 of file mwsubdiv.h.

template<int dim, class coord>
int chomp::multiwork::mwSubCoordinator< dim, coord >::sentlen [private]

The number of data packs sent for processing.

Definition at line 724 of file mwsubdiv.h.

Referenced by chomp::multiwork::mwSubCoordinator< dim, coord >::Accept(), and chomp::multiwork::mwSubCoordinator< dim, coord >::Prepare().

template<int dim, class coord>
ppCubes chomp::multiwork::mwSubCoordinator< dim, coord >::Successful[ppMaxSubdiv] [private]

The set A: Boxes which are successfully verified to satisfy the given property and thus are contained in the set A.

Definition at line 623 of file mwsubdiv.h.

Referenced by chomp::multiwork::mwSubCoordinator< dim, coord >::FailedBox(), chomp::multiwork::mwSubCoordinator< dim, coord >::GoodProbe(), and chomp::multiwork::mwSubCoordinator< dim, coord >::SuccessfulBox().


The documentation for this class was generated from the following file: