Linear programming of taxation cost on fossil fuel and green energy - linear-programming

I am currently working on a project where I am modelling a set of combined heat and power production units (CHP).
I am using linear programming to do this for now.
The main idea is to minimize the overall production cost. In order to that one must consider the taxation on the fuel type used. The general idea is that heat produced with fossil fuels will have a tax on it and power produced with green energy will have a subsidy on it.
In order to calculate this I could do the following:
FossilShare = FossilFuel / TotalFuel
FossilHeat = FossilShare * Q
GreenPower = (1-FossilShare) * P
Where P and Q are the heat and power produced. Then my taxation cost function would be as following:
Cost = FossilHeat * Tax - GreenPower * subsidy
The problem, however, is that this is not linear. I cannot think of a way to linearise this and I cannot think of another way of doing it, because I need to calculate the portion of heat produced with fossil fuel and the portion of power produced with green energy.
Any help or suggestions would be much appreciated.
Thanks in advance
M. Frank

Related

LP warehouse problem with a certain truck capacity

The problem that I need to solve is almost like the basic LP warehouse problem, where you have n warehouses, each one with a certain amount of a product, and m shops, each one demanding a certain amount of that product. So the goal is to minimize the amount of Km made by the trucks that have to deliver the products from the warehouses to the shops.
This was the easy part, I already identified the constraints and the objective function.
The part that I can't get my head around, is that the truck that delivers the products has a certain capacity, C. Every single truck has the same capacity. I can't tell if that piece of information is really relevant and should be included in some kind of constraint or something. I would really apreciate a hint, cause I've been stuck on this part for a while now and couldn't fine any example of this exact type of problem on the Internet
The number of trucs needed can be bounded by
numtrucs(i,j)*capacity >= shipment(i,j)
Add a term to the objective that minimizes the number of trucs.

Linear Programming - Re-setting a variable based on it's cumulative count

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.

Calculating speed to interval reverse ratio

This might be a slightly unusual question and I have a feeling this is a simple task and yet I struggle to find a solution.
I have an arduino project for controlling an valve based on rotational speed of a wheel. The valve needs to be opened in specific time intervals. I have a predefined maximum interval variable as well as minimum interval (both in seconds). I also have a minimum speed (in km/h), below which the valve will stay closed.
So let's assume:
min_v = 20;
max_interval = 60;
min_interval = 1;
All of the above values might possibly be change based on requirements.
How do I calculate the current opening interval based on current speed? Important thing to note is that the interval has to decrease as the speed increases.
Not sure if I also need to assume a max speed for this to be possible?
Ok so here's my formula that seems to be working:
currentInterval = maxOpeningInterval - ((maxOpeningInterval - minOpeningInterval) / (maxSpeed - minSpeed) * currentSpeed);

If Function in GAMS

I've been busy with a model, but I'm uncomfortable about the result because I think GAMS violates a constraint. What I want to tell to GAMS is:
"check demand first -> then check current stocks -> IF there is enough stocks sell from current stocks -> IF there is not enough stocks first buy (produce) then sell."
I think in the model GAMS does not obey any demand (sell), any minimum values and sells everything without buying any.
The model is hereinbelow:
Sets
i items /s,p,b/
t time in quarters /1,2,3/
Parameters
price(i) selling price per unit i per quarter in euros /s 6.34, p 6.46, b 5.93/
inistock(i) initial stock in units /s 320000, p 296199, b 104208/
cap(i) capacity limit for each unit /s 400000, p 350000, b 150000/
c cost of holding 1 unit of i /s 10, p 15, b 12/
Scalars
tcap total capacity of warehouse /650000/
Variables
stock(i,t) stock stored at time t
sell(i,t) stock sold at time t
buy(i,t) stock bought at time t
cost total cost
Positive Variables stock,sell,buy
Equations
cst total cost occurs
stck(i,t) stock balance of unit i at time t;
cst.. cost=e=sum((i,t),price(i)*(buy(i,t)-sell(i,t))+c(i)*stock(i,t));
stck(i,t).. stock(i,t)=e=inistock(i)+stock(i,t-1)+buy(i,t)-sell(i,t);
stck.up(i,t)=tcap;
Option LP=Cplex ;
Option optcr=0;
Model TWH The Warehouse Problem / all /;
Solve TWH minimizing cost using lp;
Thank you in advance for your support!
You haven't set any demand constraints, and the only minimum values are the zero bounds from defining the variables as being positive.
What other constraint did you expect GAMS to obey?
Selling everything is the correct solution to the problem you have defined.
I also think this part is a mistake:
stck.up(i,t)=tcap;
You probably meant to write 'stock' rather than 'stck'.
If this was a lower bound (writing 'lo' instead of 'up'), you would have a problem with a non-trivial solution, as you are adding a constraint that the warehouse should be filled to maximum capacity.

Individual score contributions in ML estimation

I've estimated a model via maximum likelihood in Stata and was surprised to find that estimated standard errors for one particular parameter are drastically smaller when clustering observations. I take it from the Stata manual on robust standard error estimation in ML that this can happen if the contributions of individual observations to the score (the derivative of the log-likelihood) tend to cancel each other within clusters.
I would now like to dig a little deeper into what exactly is happening and would therefore like to have a look at these score contributions. As far as I can see, however, Stata only gives me the total sum as e(gradient). Is there any way to pry the individual summands out of Stata?
If you have written your own command, you can create a new variable containing these scores using the ml score command. Official Stata commands and most finished user written commands will often have score as an option for predict, which does the same thing but with an easier syntax.
These will give you the score of the log likelihood ($\ell$) with respect to the linear predictor, $x\beta = \beta_0 + \beta_1 x_1 + \beta_2 x_2 \elipses$. To get the derivative of the log likelihood with respect to an individual parameter, say $\beta_1$, you just use the chain rule:
$\frac{\partial \ell}{\partial \beta_1} = \frac{\partial \ell }{\partial x\beta} \frac{\partial x\beta}{\partial \beta_1}$
The scores returned by Stata are $ \frac{\partial \ell }{\partial x\beta}$, and $\frac{\partial x\beta}{\partial \beta_1} = x_1$.
So, to get the score for $\beta_1$ you just multiply the score returned by Stata and $x_1$.