[gecode-users] help --- how to create an object dynamically in Gecode?

Kayler Yao risoay at gmail.com
Tue Sep 1 02:16:28 CEST 2009


hi Christian,
         You must have misunderstood my meaning. Creating an new argument
array of exactly the right size is OK. There is no problem. I want to create
an amount of new argument array that they are maybe have the same size. For
instance,
" IntArgs a1(10);
  IntArgs a2(10);
  IntArgs a3(10);
    ……"
         The amount of the variable of "IntArgs" is uncertain,which is
controlled by parameter.  The“new” way can't go, so i have to create an
certain number of variables of "IntArgs", maybe ten variables , and they
have the same size. Actually, i perhaps only use five variables. So another
five variables of "IntArgs" are waste.

hi Guido,
       I have not used it to store data. I use it to post constraints. They
are all temporary. As following example,
"
       int size = 10;
      data[10][10];

      IntVarArray result;
      result(*this,5,0,9);

      IntVarArgs a(size);
      IntArgs c(size);

     ……

      distinct(*this,result);
      for (int i = 0: i<size; i++)
       {
          c[i] = data[i][2];
       }
       element(*this, c, result[i], a[i] );
       linear(*this, a, IRT_EQ, 50);
      rel*this,result,IRT_LQ);
    "
      The part of my program is  using IntArgs like the above code lines,
the difference bettween them is that i use uncertain number of variables of
"IntArgs". I use outside parameter to control it. So creating "IntArgs" is
dynamic. There has no better way to realize it, except for creating an
certain number of variables of "IntArgs" in advance, which may waste memory.


Kayler

2009/8/31 Guido Tack <tack at ps.uni-sb.de>

> Hi Kayler,
> you should not use IntArgs for representing your data, only for posting
> constraints.  So, when you read in your data, just use e.g. normal integer
> vectors.  Then you post the constraints, and you know exactly how many you
> need.  For each posted constraint, you construct the corresponding IntArgs
> from the data vectors.  That's their purpose, don't use them for storing
> data.
>
> Guido
>
>  Kayler Yao wrote:
>
>   hi,
>     Now let me talk about what i want to do. I have a lot of data,and
> i need to copy some data into the variable of the " IntArgs ". The number of
> variables what i want is uncertain,which is controlled by an outside
> parameter. And these variables include different data.
>     For instance, i have an 10*10 Array data. Now i want to copy the second
> ,the fifth and the sixth column of Array data into three variables of
> "IntArgs". In my project, the number of  variables of "IntArgs" what i need
> and which columns of Array data i want to copy are all uncertain,controlled
> by parameters. So this case make me to search for an dynamical method to
> create variable of the "IntArgs" . But "IntArgs" do not have a new operator
> by design. So i have to change the way and create an certain number of
> variables of the "IntArgs",which is larger than actual need. You know that
> wasting memory is an obvious disadvantage of this way.
>      whether there has an better way to resolve this problem?
>
> Kayler
>
>
>
> 2009/8/30 Christian Schulte <cschulte at kth.se>
>
>>  Hi,
>>
>>
>> what’s wrong with creating a new array each time you need it? They are
>> very fast to create (they will only allocate heap memory if the array is
>> large and otherwise, creation is super-quick). I have to admit I still don’t
>> see really what you mean by uncertain number.
>>
>>
>> Best
>>
>> Christian
>>
>>
>> *From:* Kayler Yao [mailto:risoay at gmail.com]
>> *Sent:* Saturday, August 29, 2009 5:23 PM
>> *To:* Christian Schulte
>> *Cc:* users at gecode.org
>>
>> *Subject:* Re: [gecode-users] help --- how to create an object
>> dynamically in Gecode
>>>>
>>
>>
>> hi,
>>
>>    Your said about using Argument arrays are right . The purpose i use
>> Argument arrays to do is also just as it should to be . What i want to do is
>> that I want to use uncertain number of Argument Arrays ,so i want to  create
>> Argument arrays dynamically. You said that they do not have a new operator
>> by design ,so i can't use "new" way. I maybe create an certain number of
>> Argument Arrays which is much more than i want ,and it may waste some
>> memories. Whether there has another way to realize my thought?
>>
>> welcome to talk about it.
>>
>>
>> Kayler.
>>
>> 2009/8/29 Christian Schulte <cschulte at kth.se>
>>
>> Hi,
>>
>>
>> Argument arrays are meant for what they are called: passing arguments as
>> is explained in detail in Section 4.2.2 in Modeling with Gecode. Using them
>> for other purposes is a bad idea and hence they do not have a new operator
>> by design!
>>
>>
>> What you should do is use a different data structure and create and
>> argument array just when you need it for posting a propagator or branching.
>>
>>
>> Christian
>>
>>
>> *From:* users-bounces at gecode.org [mailto:users-bounces at gecode.org] *On
>> Behalf Of *Kayler Yao
>> *Sent:* Saturday, August 29, 2009 5:20 AM
>> *To:* users at gecode.org
>> *Subject:* Re: [gecode-users] help --- how to create an object
>> dynamically in Gecode?
>>
>>
>> hi,
>>
>>   And i find that "Gecode::Support::DynamicArray< T, A > Class Template"
>> maybe can realize it. But i did it  unsuccessfully.
>>
>> Who can give me right answer.
>>
>>
>> Kayler
>>
>> 2009/8/29 Kayler Yao <risoay at gmail.com>
>>
>> hi,
>>
>>     I want to create an object of IntArgs in my program dynamically. For
>> instance " IntArgs *pt = new IntArgs(4); -----create an object of IntArgs
>> with four elements" or
>>
>> "IntArgs *pt = new IntArgs [10];------create an array with 10 object of
>> IntArgs." They all be compiled with errors. And i haven't seen the examples
>> of create object dynamically in Gecode. And I want to know whether the
>> Gecode support to create object of Gecode class ? And how ?
>>
>> Look forward to your reply!
>>
>>
>> Kayler
>>
>>
>>
>
> _______________________________________________
> 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.ps.uni-sb.de/pipermail/users/attachments/20090901/d681227d/attachment.htm>


More information about the gecode-users mailing list