Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Over view
I am trying to create a game that would need a pseudo-random function of the following characteristics:
Each player would be allotted a variable (of type float) for their money, the products (of type int*) they own and would want to sell and another variable to show what place they are in.
Each player would have the right to sell any of their products they own to any other player; and in addition the game involves a computer player which represents the other citizen population of that place who would want to buy the products or sell certain products.
Each player would have a different place value and each place would have different different cost for each products and the "transport cost" between different places also differs as a function of time.
A brief data structure of a player's profile would is as follows:
typedef struct PLAYER{
char *name;
int place;
int *products;
int noOfProducts;
float money;
PLAYER();
PLAYER(&ply);
.
.
.
}*ptrPLAYER;
Now I need a pseudo-random function that sets the rate of each product, rate of transport from one place to the other, and the function should also determine what products should the "citizens" player buy or sell and at what rate. The values provided by this function should follow a particular trend for some time and change its trend completely, but the variance should not be high. characteristics of the pseudo function:
Should be the function of the previous values generated and time.
Should show a gradual change following some trend up to some point.
The question:
The random function should have the following properties:
The variance should be low.
If we define the function as int *randomFnc( int previousResult[]) the function should follow some trend being very difficult to crack and at the same time, it should not reach a saturation point where beyond that point, the randomFnc(.) provides the same result.
The random function should generate a set of values (for example 100 values) which are directly dependent upon the previously generated values in some unique way.
You can model your process. As a starting point you can choose autoregressive model of type AR(1):
y_t = a_0 + a_1 * y_(t-1) + e_t (1)
where y is your variable of interest, e_t is gaussian white noise with mean 0 and variance sigma_e_t^2 and a0, a1 are constants.
should be the function of the previous values generated and time.
You can generate number of N of white noise assuming you will need N values of y. Then as you can see, value of y in time t is directly dependent on previous value y_(t-1) and you can always switch between two based on your array of e_t and relation (1).
the variance should be low.
The unconditional variance of y_t is
var(y_t) = sigma_e_t^2 / ( 1 - a_1^2) if a_1^2 < 1
so you can make it as small as you would like ( in range [sigma_e_t^2, +inf)) .
This process may looks like
You can add trend to make it y_t = a_0 + a_1 * t + a_2 * y_(t-1) + e_t and it will looks something like
More details are needed to be added in your question in order to advise you how to adjust this process further being subjected to other restrictions.
Related
Detailed business problem:
I'm trying to solve a production scheduling business problem as below:
I have two plants producing FG A and B respectively.
Both the products consume the same Raw Material x
I need to create a 30 day production schedule looking at the Raw Material availability.
FG A and B can be produced if there is sufficient raw material available on the day.
After every 6 days of production the plant has to undergo maintenance and the production on that day will be zero.
Objective is to maximize the margin looking at the day level Raw material available and adhere to the production constraint (i.e. shutdown after every 6th day)
I need to build a linear programming to address the below problem:
Variable y: (binary)
variable z: cumulative of y
When z > 6 then y = 0. I also need to reset the cumulation of z after this point.
Desired output:
How can I build the statement to MILP constraint. Are there any techniques for solving this problem. Thank you.
I think you can model your maintenance differently. Just forbid any sequences of 7 ones for y. I.e.
y[t-6]+y[t-5]+y[t-4]+y[t-3]+y[t-2]+y[t-1]+y[t] <= 6 for t=1,..,T
This is easier than using your accumulator. Note that the beginning needs some attention: you can use historic data for this. I.e., at t=1, the values for t=0,-1,-2,.. are known.
Your accumulator approach is not inherently wrong. We often use it to model inventory. An inventory capacity is a restriction on how large the accumulated inventory can be.
I am trying to perform a sample size calculation in SAS for a two sample time to event case.
Here is the situation:
Assume both sample follows exponential distribution
Assume a given constant hazard ratio under alternative hypothesis, we call hr (group 2 vs group 1)
We will use logrank test.
Given accrual time a, and follow up time f
Also given the exponential hazard for group 1, called it exph1
Assume the sample size ratio between the two group is 1:1
required nominal power is p
Now my code looks like this:
proc power;
twosamplesurvival test=logrank
accrualtime = a
followuptime = f
refsurvexphazard= exph1
hazardratio = hr
power = p
/* eventstotal = . /*events total */
/* ntotal= . /*total sample size */
;
run;
you can uncomment either eventstotal = . or ntotal=. depending on whether you want to compute the requested number of events, or the actual total sample size.
They should not be the same consider by the end of follow up, if the event does not happen, then the subject will be right censored.
However I am always getting the same number for events total and total sample size. What did I do wrong here?
I actually know how to compute this by hand, and my hand calculation for requested event number is very close to SAS output (SAS gives a slightly larger value but very close), however my total sample size is much larger than the event number.
I could not disclose any particular initial value for the parameters above due to confidential reasons. Could someone help? Would really appreciate that.
Okay, so this is going to be very complicated to explain through text but I will do my best to try.
I am making a universal calculator where one of the function of the calculator is to process a formula when given an unknown number of variables. I have seen some ways to do this but for how i'm trying to use this calculator, it wont work.
Example for sum of function:
while (cin >> input)
count++;
Normally this would work but the problem is that I can't have the user input the values over and over again for one formula like for this formula: Formula Example
(Sorry its easier for me to explain through a picture) In it there are multiple times where I have to use the same numbers over and over again. Here is the entire process if you need it to understand what I'm saying:
Entire problem
The problem is that normally I would add another float for every point graph but I don't know ahead of time number of floats the user is going to enter in. The ideal way to do this is for the program to ask the user for all the points on the table and for the user to input those points in a format like: "(1,2) (2,4) (3,6)..."
Thinking ahead, would I make a function where the program creates an integer and assigns the integer to a value on the fly? But then how would the actual math formula interact with the new integers if they haven't been created yet?
Talking about this makes my head hurt....
I actually want to say more:
One idea that I tried to make in my head was something like
string VariableName = A [or something]
Then you would reassign VariableName = "A" to VariableName = "B" by something like VariableName = "A"+ 1 (which would equal B).
Then you would repeat that step until the user inputs a invalid input. But obviously you can't do math with letters so I wouldn't know how to do it.
I think that you are overthinking this. It's pretty simple and it doesn't need to store the input values.
The main thing to note is that you need to compute (step 2) the sum of the values of X and Y, the sum of their product and the sum of X squared. To compute the sum of a lot of values you don't need all the values together, but just one at the time. Exactly as when a user provides them. So declare four variables: sx, sy, sxy, sxx. Initialize them to 0. At every couple of X and Y you get, add it to sx and sy, add their product to sxy and the product of X with itself to sxx.
Now you've got all you need to compute the final result for a and b.
Anyway a good C++ book would be useful.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I'm practicing with classes and I'm given the task of creating employee management system. I'm given two .txt files. One (details.txt) has details of each employee with the following info: ID, name, DOB, SSN, department, and position. A sample of the file looks like such:
5 ali 6/24/1988 126-42-6989 support assistant
13 tim 2/10/1981 131-12-1034 logistics manager
The other .txt (timelog.txt) will contain a daily log of when employees clock in and clock out. The following format for this file is: ID, date, clock in time, and clock out time. Sample:
5 3/11 0800 1800
13 3/11 0830 1830
Firstly, I am to allow users to search up an employee by ID, name, department or position. Doing so will display all of the employees info (multiple employees if they have the same name, position or are from the same department) as well as show the total number of hours they have worked in the company.
Secondly, users are to be given another option to look up employee time logs by ID number. This will display the entire clock in/ clock out history of that employee as well as total hours worked each day.
I'm planning to read in the info from .txt files via ifstream and store them as an array of objects. I'm just wondering how many classes I should create. I'm thinking 2 classes- one for employee info (from details.txt) and one for time logs(timelogs.txt). Is there any other class I should create or should those 2 suffice?
Short answer: At least two.
Long answer: It depends on many things. Especially what part of code you can identify as potentially reusable.
If you asked for the highest possible amount of classes that could accomplish your task, I would think about a single class for:
Employee
EmployeeManager (Factory, Holder etc.) – creates, holds and deletes the Employee objects, provides search feature
DayWork – a row from timelog.txt, can calculate the amount of hours/minutes spent in work that day
WorkLog – a list of DayWork objects for one employee, can calculate the whole spent time
TextLineParser – encapsulation of std::ifstream
The right answer is most likely somewhere between. Keep in mind that C++ is a multi-paradigm language and you can perform some operations without having a class for them. Instead, they can be performed in a function or a set of functions in a C-like unit. That’s especially useful for one-time operations where the functions don’t share common data (potential properties).
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm trying to create a structure that contains fields for account numbers, balances, and interest rates and I am supposed to use an array to do so.
I need the output to display like this:
Account number X has a balance of X and an interest rate of X.
The end user is supposed to be able to enter their account number (and if it's already in the system an error message should occur) their balance and their interest rate.
I'm stuck! I don't know if I should create some sort of parallel array or some sort of dimensional array (two-dimensional, three-dimensional, I don't know).
____UPDATE___
First of all- I'm 4 weeks into my first programming class ever- The text asks me to complete the tasks I will share below. We have not learned about std:... & vectors yet. This chapter covered parallel arrays and structure objects. But the only thing I've learned about structure objects is this:
struct Part
{
int partNum;
double partPrice;
};
The rest of the above code just shows me how to enter in info as a programmer and not how to allow the user to enter in code.
You are developing a BankAccount structure for Parkville Bank. The structure contains
fields for the account number, the account balance, and the annual interest rate earned on
the account. Write a main()function in which you create an array of five BankAccount
objects. Prompt the user for values for all the fields in the five BankAccounts. Do not
allow two or more accounts to have the same account number. After all the objects have
been entered:
» Display all the data for all five accounts.
» Display the total balance in all five accounts and the average balance.
» After displaying the statistics, prompt the user for an account number and display the
data for the requested account, or display an appropriate message if no such account
number exists. Continue to prompt the user for account numbers until an appropriate
sentinel value is entered.
Based on this: "I don't know if I should create some sort of parallel array or some sort of dimensional array (two-dimensional, three-dimensional, I don't know)" it seems like you are completely confused about how this kind of data can be grouped. One of the many possible ways is:
struct Account {
std::string number;
double balance;
double interestRate;
};
representing a single element that can be used in some container holding accounts, e.g. :
std::vector<Account> accounts;
but since you mentioned the constraint: "I am supposed to use an array to do so", then unfortunately you'll have to use a C-style array:
Account accounts[N];
or in case you have no VLA support:
Account* accounts = new Account[N];
...
delete[] accounts;
Now get some good book and spend some time reading it before you continue writing codes.