[gecode-users] Updating Variables stored in a STL-Vector

Guido Tack tack at gecode.org
Mon Apr 22 05:14:37 CEST 2013


Hi,

I'm not sure why you're assigning the vectors from s to the vectors from this.  You should instead create new vectors with the same capacity, probably somewhat like this:

listVarMachines = vector<IntVarArgs>(s.listVarMachines.size());

Otherwise you're updating into the same data structures.

Cheers,
Guido

On 22/04/2013, at 12:43 PM, Holmes Giovanny Salazar Osorio <hgsosorio at gmail.com> wrote:

> addin the list to the loop...
> 
> ---------- Forwarded message ----------
> From: Holmes Giovanny Salazar Osorio <hgsosorio at gmail.com>
> Date: 2013/4/21
> Subject: Re: [gecode-users] Updating Variables stored in a STL-Vector
> To: cschulte at kth.se
> 
> 
> Hello, I've changed some things in my code, and now, the program finishes unexpectedly when it is trying to update the variables stored in the STL-Vector.
> 
> now, I have the update function in this way:
> 
> MyClass(bool share, MyClasss) : MaximizeScript(share, s) {
> 
>     listVarMachines = s.listVarMachines;
>     listVarTStarts = s.listVarTStarts;
>     listVarTEnds = s.listVarTEnds;
>     listDuration = s.listDuration;
>     listResources = s.listResources;
>     listMachinesCapacity = s.listMachinesCapacity;
> 
>     for( int i=0; i < size; i++)
>     {
>         listVarMachines[i].update(*this, share,  s.listVarMachines[i])
> ;
>         listVarTStarts[i].update(*this, share,  s.listVarTStarts[i]);
>         listVarTEnds[i].update(*this, share,  s.listVarTEnds[i]);
>         listDuration[i] = s.listDuration[i];
>         listResources[i] = s.listResources[i];
>         listMachinesCapacity[i] = s.listMachinesCapacity[i];
>     }
> }
> 
> Debugging with eclipse, I could find that when Gecode is updating the first vector:
> 
> listVarMachines[i].update(*this, share,  s.listVarMachines[i]);
> 
> It finishes unexpectedly, exactly when Gecode is executing this code:
> 
>   template<class Var>
>   forceinline void
>   VarArray<Var>::update(Space& home, bool share, VarArray<Var>& a) {
>     n = a.n;
>     if (n > 0) {
>       x = home.alloc<Var>(n);
>       for (int i = n; i--;)
>         x[i].update(home, share, a.x[i]);
>     } else {
>       x = NULL;
>     }
>   }
> 
> in the file array.hpp (more or less between the lines 1052 and 1063).
> 
> Thanks in advice for your help. Best regards,
> 
> Holmes
> 
> 
> 2013/4/17 Christian Schulte <cschulte at kth.se>
> I can’t really see the error. What happens if you just use a single machine?
> 
>  
> 
> Do you really have to use cumulatives? Would cumulative work instead?
> 
>  
> 
> Christian
> 
>  
> 
> --
> 
> Christian Schulte, www.ict.kth.se/~cschulte/
> 
>  
> 
> From: Holmes Giovanny Salazar Osorio [mailto:hgsosorio at gmail.com] 
> Sent: Wednesday, April 17, 2013 3:26 PM
> To: cschulte at kth.se
> Cc: users at gecode.org
> Subject: Re: [gecode-users] Updating Variables stored in a STL-Vector
> 
>  
> 
> Hello Christian,
> 
> I wrote bad the code in the mail, but in my class I update the variables in this way,
> 
> listVarMachines[i].update(*this, share,  s.listVarMachines[i]); 
> 
> I'm initializing the stl-vectors that contain IntArgs in this way:
> 
> listResources.push_back(IntArgs(size, anIntegerArray));
> 
> And the stl-vectors that contain IntVarArray in this way:
> 
> for the machines:
> 
> listaVarMachines.push_back(IntVarArray(*this, size, anIntSet));
> 
> for the times of the tasks:
> 
> listVarTStart.push_back(IntVarArray(*this, size, 0, MAX-MAKESPAN));
> 
> MAX-MAKESPAN is an int. Take values > 500, it depends of the problem to solve.
> 
> Thanks a lot for helping me. Best regards,
> 
> Holmes
> 
> 
> 2013/4/17 Christian Schulte <cschulte at kth.se>
> 
> Yes, the update is definitely wrong, the code you sent should not even compile, it must be:
> 
>                listVarMachines[i].update(*this, share,  s.listVarMachines[i]);
> 
> instead of
> 
>                listVarMachines.update(*this, share,  s.listVarMachines[i]);
> 
> and so on.
> 
>  
> 
> Then, do you initialize the variable and integer arrays properly?
> 
>  
> 
> Christian
> 
>  
> 
> --
> 
> Christian Schulte, Professor of Computer Science, KTH,  www.ict.kth.se/~cschulte/
> 
>  
> 
>  
> 
> From: users-bounces at gecode.org [mailto:users-bounces at gecode.org] On Behalf Of Holmes Giovanny Salazar Osorio
> Sent: Wednesday, April 17, 2013 6:06 AM
> To: users at gecode.org
> Subject: [gecode-users] Updating Variables stored in a STL-Vector
> 
>  
> 
> Hello all,
> 
> I have Gecode 3.7.3 on Ubuntu. I'm working in a scheduling problem with optmization, therefore, I'm using MaximizeScript and the cumulatives constraint.
> 
> Right now, I'm having problems with the cumulatives constraint, because, It doesn't works properly. I have something like 
> 
> take into account that: size = listVarMachines.size = listVarTStarts = listVarTEnds = listDuration = listResources = listMachinesCapacity
> 
> for(int i = 0; i < size; i++){
>     cumulatives(
>         *this,
>         listVarMachines[i],
>         listVarTStarts[i],
>         listDuration[i],
>         listVarTEnds[i],
>         listResources[i],
>         listMachinesCapacity[i],
>         true,
>         ICL_BND);
> }
> 
> where listVarMachines, listVarTStarts, listVarTEnds are declared in this way -> vector<IntVarArray> listVar...
> 
> And listDuration, listResources and listMachinesCapacity are declared in this way -> vector<IntArgs> list...
> 
> When I force the elements in the vector listMachinesCapacity to take a value of 1. The program assign more than 1 task at the same time. This is wrong, because with the Limit of resource equals to 1, the cumulatives constraint should assign one and only one task in the same unit of time.
> 
> I think that the problems is that the cumulatives constraint isn't being propagated for any reason. And I have doubts with the way in that the variables are being updated. 
> 
> In the update function I have something like this:
> 
> MyClass(bool share, MyClasss) : MaximizeScript(share, s) {
> 
>     listVarMachines = s.listVarMachines;
>     listVarTStarts = s.listVarTStarts;
>     listVarTEnds = s.listVarTEnds;
>     for( int i=0; i < size; i++)
>     {
>         listVarMachines.update(*this, share,  s.listVarMachines[i]);
>         listVarTStarts.update(*this, share,  s.listVarTStarts[i]);
>         listVarTEnds .update(*this, share,  s.listVarTEnds[i]);
>     }
> }
> 
> Dou you think that the problem can be the way of I'm updating the variables, or do you have another idea?
> 
> 
> Thank you in advance!. Best regards,
> 
> Holmes
> 
> --
> 
> "El secreto del éxito, está en la disciplina"
> 
> Holmes Giovanny Salazar Osorio
> 
> Ingeniería de Sistemas
> 
> Estudiante 10mo Semestre
> 
> Universidad del Valle - Sede Tuluá
> 
> 
> 
> 
> --
> 
> "El secreto del éxito, está en la disciplina"
> 
> Holmes Giovanny Salazar Osorio
> 
> Ingeniería de Sistemas
> 
> Estudiante 10mo Semestre
> 
> Universidad del Valle - Sede Tuluá
> 
> 
> 
> 
> -- 
> "El secreto del éxito, está en la disciplina"
> Holmes Giovanny Salazar Osorio
> Ingeniería de Sistemas
> Estudiante 10mo Semestre
> Universidad del Valle - Sede Tuluá
> 
> 
> 
> -- 
> "El secreto del éxito, está en la disciplina"
> Holmes Giovanny Salazar Osorio
> Ingeniería de Sistemas
> Estudiante 10mo Semestre
> Universidad del Valle - Sede Tuluá
> _______________________________________________
> Gecode users mailing list
> users at gecode.org
> https://www.gecode.org/mailman/listinfo/gecode-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.gecode.org/pipermail/users/attachments/20130422/bbed869c/attachment-0001.html>


More information about the users mailing list