[gecode-users] Bug in linear contraint?

Tales Pinheiro de Andrade tales at talesp.inf.br
Sun Sep 5 22:30:31 CEST 2010


Hello,

First, sorry about my English, I don't  write English so well.

I'm a newbie in Gecode and contraint programming, and I'm geting  a strange error, but I don't know if it is a bug or error.

I have  a bidimensional vector filled with 0 and 1 called serie representing the time series of a boolean network. Based in the content, I try to determine the network.

I have a few linear constrints based in the content of serie. But there is a case that, when I post a linear constrint, all the constraint of the space is erased. The constrint in case is in the line marked with * in the code.

Here is the code:

class Instancia {
public:
    std::vector<std::vector<int > >serie;
    int num_estados;
    int num_genes;
    int gene;
};


namespace {
    Instancia instancia;
}

class TimeSeries : public Script {
private:
    IntVarArray array;
    std::vector<std::vector<int > >serie;
    
    const int num_estados;
    const int num_genes;
    const int gene;
public:
        /// Post constraints
    TimeSeries(const Options& opt)
    :array(*this, instancia.num_genes, -1, 1),
    serie(instancia.serie),
    num_estados(instancia.num_estados),
    num_genes(instancia.num_genes),
    gene(instancia.gene)
    {
        for (int i = 1; i < num_estados - 1; i++)
        {
            int num_genes_diff = 0, gene_diff = num_genes + 1;
			for (int j = 0; j < num_genes; j++)
            {
		if (serie[i-1][j] != serie[i][j])
                {
		    num_genes_diff++;
		    gene_diff = j;
		}
	    }
            if (num_genes_diff == 1 && gene_diff == gene)
            {
		for (int j = 0; j < num_genes; j++)
                {
                    if (serie[i+1][j] > serie[i][j])
                    {
                        rel(*this, array[j], IRT_EQ, 1);
                    }
                    else if (serie[i+1][j] < serie[i][j])
                    {
                        rel(*this, array[j], IRT_EQ, -1);
                    }
                }
            }
        }

            //passo 2
        for (int t = 0; t < num_estados-1; t++)
        {
            IntArgs x_it(num_genes);
            int i = gene;
            for (int j = 0; j < num_genes; j++)
            {
                x_it[j] = serie[t][j];
            }
            
            if (serie[t][i] == 0 && serie[t + 1][i] == 0)
            {
                linear(*this, x_it, array, IRT_LQ, 0, opt.icl());
            }
            else if (serie[t][i] == 0 && serie[t+1][i] == 1)
            {
                linear(*this, x_it, array, IRT_GR, 0, opt.icl());
            }
            else if (serie[t][i] == 1 && serie[t+1][i] == 0)
            {
                linear(*this, x_it, array, IRT_LE, 0, opt.icl());
            }
            else
            {
                linear(*this, x_it, array, IRT_GQ, 0, opt.icl());
            }
        }
        
            //passo 3
        for (int a = 0; a < num_estados - 2; a++)
        {
            for ( int b = a+1; b < num_estados - 1; b++)
            {
                IntArgs x_it(num_genes * 2);
                IntVarArgs a_ij = array + array;

                for (int j = 0; j < num_genes; j++)
                {
                    if (serie[a][j] == 1 && serie[b][j] == 0)
                    {
                        x_it[j] = serie[a][j];
                    }
                    else {
                        x_it[j] = 0;
                    }
                    
                    if (serie[b][j] == 1 && serie[a][j] == 0)
                    {
                        x_it[num_genes + j] = -serie[b][j];
                    }
                    else {
                        x_it[j + num_genes] = 0;
                    }
                }
                
                if (serie[a][gene] == 1 && serie[a+1][gene] == 0)
                {
                    if ((serie[b][gene] == 0 && serie[b+1][gene] == 1) ||
                        (serie[b][gene] == 1 && serie[b+1][gene] == 1))
                    {
                        int prop=0;
                        for (Propagators p(*this); p(); ++p)
                            prop++;
                        std::cout << "Prop: " << prop << std::endl;
                        std::cout << std::endl;
                            //rest 1 e 8
***                     linear(*this, x_it, a_ij, IRT_LE, 0, opt.icl());
                        prop=0;
                        for (Propagators p(*this); p(); ++p)
                            prop++;
                        std::cout << "Prop: " << prop << std::endl;
                        std::cout << std::endl;
                        
                    }
                }else if (serie[a][gene] == 0 && serie[a+1][gene] == 1)
                {
                    if ((serie[b][gene] == 0 && serie[b+1][gene] == 0) ||
                        (serie[b][gene] == 1 && serie[b+1][gene] == 0))
                    {
                            //rest 2 e 5
                        for ( int i = 0; i < x_it.size(); i++)
                        {
                            x_it[i] = -1 * x_it[i];
                        }
                        linear(*this, x_it, a_ij, IRT_LE, 0, opt.icl());
                    }                    
                }
                else if (serie[a][gene] == 1 && serie[a+1][gene] == 1)
                {
                    if (serie[b][gene] == 0 && serie[b+1][gene] == 0)
                    {
                            //rest 3
                        for ( int i = 0; i < x_it.size(); i++)
                        {
                            x_it[i] = -1 * x_it[i];
                        }
                        linear(*this, x_it, a_ij, IRT_LQ, 0, opt.icl());
                    }
                    else if (serie[b][gene] == 1 && serie[b+1][gene] == 0)
                    {
                            //rest 6
                        for ( int i = 0; i < x_it.size(); i++)
                        {
                            x_it[i] = -1 * x_it[i];
                        }
                        linear(*this, x_it, a_ij, IRT_LE, 0, opt.icl());
                    }
                }
                else if (serie[a][gene] == 0 && serie[a+1][gene] == 0)
                {
                    if (serie[b][gene] == 0 && serie[b+1][gene] == 1)
                    {
                            //rest 4
                        linear(*this, x_it, a_ij, IRT_LE, 0, opt.icl());
                    }
                    else if (serie[b][gene] == 1 && serie[b+1][gene] == 1)
                    {
                            //rest 7
                        linear(*this, x_it, a_ij, IRT_LQ, 0, opt.icl());
                    }
                }
            }
        }

        branch(*this, array, INT_VAR_SIZE_MIN, INT_VAL_SPLIT_MIN);
    }
        /// Constructor for cloning \a s
    TimeSeries(bool share, TimeSeries& s) : Script(share,s), 
    num_genes(s.num_genes), num_estados(s.num_estados), 
    gene(s.gene), serie(s.serie)
    {
        array.update(*this, share, s.array);
    }
    
        /// Copy during cloning
    virtual Space*
    copy(bool share)
    {
        return new TimeSeries(share,*this);
    }
        /// Print solution
    virtual void
    print(std::ostream& os) const
    {
        os << "\t" << array << std::endl;
    }
    
};

And here is part of the main function:

    instancia.serie = serie;
    instancia.num_genes = estado.size();
    instancia.num_estados = serie.size();
    
    Options opt("TimeSeries");
    opt.solutions(1000);
        //opt.time(1000);
    opt.threads(0);
    opt.iterations(10);
    opt.parse(argc,argv);
    
    for (int i = 0; i < instancia.num_genes; i++)
    {
        unsigned int n_p = t->propagators();
        unsigned int n_b = t->branchers();
                    
        TimeSeries* t = new TimeSeries(opt);
        DFS<TimeSeries> e(t,so);

So, in the serie vector, gene is the column. I'm comparing to lines of the vector and deciding which constraint to post. But with only a column the constraints are erased, for all other columns/constraints its OK.

I'm running in a Mac with Gecode 3.4.

Thanks

Tales
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.gecode.org/pipermail/users/attachments/20100905/6c0bcc79/attachment-0001.htm>


More information about the users mailing list