Mar-05-2021, 04:10 PM
Suppose, I have a set A={'a','b','c'}. I want to declare variables look like N_a, N_b, N_c for every 'a','b','c' in A. Thanks in advance.
Variable declaration
|
Mar-05-2021, 04:10 PM
Suppose, I have a set A={'a','b','c'}. I want to declare variables look like N_a, N_b, N_c for every 'a','b','c' in A. Thanks in advance.
Mar-05-2021, 04:17 PM
Why? What are you actually trying to achieve?
Mar-05-2021, 04:28 PM
(Mar-05-2021, 04:17 PM)ndc85430 Wrote: Why? What are you actually trying to achieve?For example, I have a relation looks like- a:- b,c,0.8 (called rule in possibilisitcs answer set programming). I like to transfer this relation into an inequality looks like N_a >= min(N_b,N_c,0.8) where N_a, N_b, N_c are variables. We can do it manually but for 100 or 1000 rules how could do that by machine?
Mar-05-2021, 05:22 PM
For such a large number of values, better use a data structure, such as a list.
If positions of values have some meaning, then using list with indexing should do it for you.
Mar-05-2021, 09:26 PM
(This post was last modified: Mar-05-2021, 09:26 PM by deanhystad.)
Do you want to generate code or make variables? Making variables isn't very useful because it is easier to keep track of collections of variables than trying to figure out a way to get the correct attribute name. It is easy to make programmatically create a variable named 'N_a', but it is difficult for anyone to know that 'N_a' exists, and even harder to make something like N_a >= min(N_b,N_c,0.8).
When you say "We can do it manually", what do you mean? How are you doing this manually? I know of no way to manually make variables unless I am running an interactive interpreter. I know how to write code that makes variables. I even know how to write code that knows how to write code.
Mar-25-2021, 05:31 PM
|
|
Possibly Related Threads… | |||||
Thread | Author | Replies | Views | Last Post | |
dynamic variable name declaration in OOP style project problem | jacksfrustration | 3 | 717 |
Oct-22-2023, 10:05 PM Last Post: deanhystad |
|
Help in Class declaration | KranthiYamanki | 1 | 1,854 |
May-30-2019, 10:51 AM Last Post: heiner55 |
|
makingVariable declaration mandatory | rohitnirantar | 5 | 2,969 |
Aug-26-2018, 08:00 AM Last Post: Gribouillis |