I have created this if and else if statements. Flat, Vertical, Facedown, Right Side, and Left Side work... However, I am not sure why the Upside down is not working. Here is my code:
checkOrientation= () => {
let orientation = "unknown";
if (z > .8 && Math.abs(x) < .2 && Math.abs(y) < .2) orientation = "flat";
else if (y > .9 && Math.abs(x) < .2 &&Math.abs(z) < .2) orientation = "vertical";
if (x < .1 && Math.abs(y) < .1 && Math.abs(z) < .3) orientation = "right side";
else if (z < .01 && Math.abs(x) > .9 && Math.abs(y) < .05) orientation = "left side";
if (x > .01 && Math.abs(y) < .7 && Math.abs(z) < .05) orientation = "upside down";
else if (x > .01 && Math.abs (y) < .01 && Math.abs(z) > .01) orientation = "face down";
this.setState({orientation});
}
Related
I am trying to run a parameter variation experiment with 3 iterations and 100 replications in Anylogic. I use the same 100 seeds {10, 20, 30, ..., 1000} for every replication using
root.getDefaultRandomGenerator().setSeed((long) listOfSeeds.get(getCurrentReplication()));
in "before simulation run" java action field in parameter variation properties. I am varying one parameter. For retrieving data after each run I inserted following code in "after simulation run" section
replication = getCurrentReplication();
double totalMins = 0;
double totalLoading = 0;
double totalUnloading = 0;
int i = 0;
while(i < root.pickTime.size()){
double x = root.pickTime.getX(i);
if(i+7 < root.pickTime.size() && x == root.pickTime.getX(i+1) && x == root.pickTime.getX(i+2) && x == root.pickTime.getX(i+3) && x == root.pickTime.getX(i+4) && x == root.pickTime.getX(i+5) && x == root.pickTime.getX(i+6) && x == root.pickTime.getX(i+7)){
double y = root.pickTime.getY(i) + root.pickTime.getY(i+1) + root.pickTime.getY(i+2) + root.pickTime.getY(i+3) +root.pickTime.getY(i+4) +root.pickTime.getY(i+5) +root.pickTime.getY(i+6) +root.pickTime.getY(i+7);
pickTimePV.add(x, y);
i += 8;
continue;}
if(i+6 < root.pickTime.size() && x == root.pickTime.getX(i+1) && x == root.pickTime.getX(i+2) && x == root.pickTime.getX(i+3) && x == root.pickTime.getX(i+4) && x == root.pickTime.getX(i+5) && x == root.pickTime.getX(i+6)){
double y = root.pickTime.getY(i) + root.pickTime.getY(i+1) + root.pickTime.getY(i+2) + root.pickTime.getY(i+3) +root.pickTime.getY(i+4) +root.pickTime.getY(i+5) +root.pickTime.getY(i+6);
pickTimePV.add(x, y);
i += 7;
continue;}
if(i+5 < root.pickTime.size() && x == root.pickTime.getX(i+1) && x == root.pickTime.getX(i+2) && x == root.pickTime.getX(i+3) && x == root.pickTime.getX(i+4) && x == root.pickTime.getX(i+5)){
double y = root.pickTime.getY(i) + root.pickTime.getY(i+1) + root.pickTime.getY(i+2) + root.pickTime.getY(i+3) +root.pickTime.getY(i+4) +root.pickTime.getY(i+5);
pickTimePV.add(x, y);
i += 6;
continue;}
if(i+4 < root.pickTime.size() && x == root.pickTime.getX(i+1) && x == root.pickTime.getX(i+2) && x == root.pickTime.getX(i+3) && x == root.pickTime.getX(i+4)){
double y = root.pickTime.getY(i) + root.pickTime.getY(i+1) + root.pickTime.getY(i+2) + root.pickTime.getY(i+3) +root.pickTime.getY(i+4);
pickTimePV.add(x, y);
i += 5;
continue;}
if(i+3 < root.pickTime.size() && x == root.pickTime.getX(i+1) && x == root.pickTime.getX(i+2) && x == root.pickTime.getX(i+3)){
double y = root.pickTime.getY(i) + root.pickTime.getY(i+1) + root.pickTime.getY(i+2) + root.pickTime.getY(i+3);
pickTimePV.add(x, y);
i += 4;
continue;}
if(i+2 < root.pickTime.size() && x == root.pickTime.getX(i+1) && x == root.pickTime.getX(i+2)){
double y = root.pickTime.getY(i) + root.pickTime.getY(i+1) + root.pickTime.getY(i+2);
pickTimePV.add(x, y);
i += 3;
continue;}
if(i+1 < root.pickTime.size() && x == root.pickTime.getX(i+1)){
double y = root.pickTime.getY(i) + root.pickTime.getY(i+1);
pickTimePV.add(x, y);
i += 2;
continue;}
else{
pickTimePV.add(x, root.pickTime.getY(i));
i++;}}
excelFile.writeDataSet(pickTimePV, 1, 1, 1 + iteration);
pickTimePV.reset();
iteration +=3;
kommiUtilization.add(getCurrentIteration(), root.kommiPool.utilization());
aushilfeUtilization.add(getCurrentIteration(), root.aushilfePop.get(0).timeInState(ResourceUsageState.USAGE_BUSY, MINUTE) / (root.kommissionierer.get(0).timeInState(ResourceUsageState.USAGE_BUSY, MINUTE)/root.kommiPool.utilization()));
ordersInQueue.add(getCurrentIteration(), root.orderQueue.size());
for(int j = 0; j < root.loadingTime.size(); j++){
totalLoading += root.loadingTime.getY(j);}
loadingTimePV.add(getCurrentIteration(), totalLoading/root.totalLoadTrucks);
for(int k = 0; k < root.unloadingTime.size(); k++){
totalUnloading += root.unloadingTime.getY(k);}
unloadingTimePV.add(getCurrentIteration(), totalUnloading/root.totalUnloadTrucks);
for(int t = 0; t < root.pickTime.size(); t++){
totalMins += root.pickTime.getY(t);}
totalPickTime.add(getCurrentIteration(), totalMins);
totalLoadTrucksPV.add(getCurrentIteration(), root.totalLoadTrucks);
totalUnloadTrucksPV.add(getCurrentIteration(), root.totalUnloadTrucks);
After replication No. 61 (183 simulation runs) the system throws the error:
Error in the model during iteration 3
java.lang.RuntimeException: Error in the model during iteration 3
at com.anylogic.engine.ExperimentParamVariation$b.i(Unknown Source)
at com.anylogic.engine.n$b.run(Unknown Source)
Before the error occurs, the last simulation run finishes succesfully (visibile using traceln()). I checked all possible parameter configurations and seed numbers where the error could be thrown with simulation experiments, but everything works fine for simulation experiments. So I guess the error has to do something with the parameter variation experiment setup.
Do you have any ideas how to fix the problem?
Thanks in advance.
I have below code:
<image
id="wheel-bg"
class="wheel-bg"
:x="-width/2"
:y="-height/2"
href="images/wheel-bg.png"
:width="width"
:height="height"
filter="drop-shadow(black 0px 0px 1rem)"
#click="spin"
></image>
I have a data property "rotationState" which can be "false" or "true".
rotationState = false means #click event should fire and
rotationState = true means #click event should not fire
I tried
#click="spin && rotationState"
I also tried:
#click.stop="rotationState"
#click="spin"
and
:disabled="rotationState"
but above methods don't work because I think I have #click event on an <image></image> element.
What I am trying to achieve is basically,
container.on('click', null); this is the code that was used when I first wrote the code in jquery / js.
Jquery Spin function code
container.on("click", spin); //this code triggers spin in jquery
function spin(d) {
container.on("click", null); //this code disables multiple spin from happening
spinCount++;
// First 2 spins
if (spinCount < totalSpins) {
//get random number of rotations + get random degree for "No Win"
// 1 to 28 or 211 to 239 deg
if (Math.random() < 0.5) {
rotation = ((Math.floor(Math.random() * 1) + 3) * 360) + (Math.floor(Math.random() * 28) + 1);
} else {
rotation = ((Math.floor(Math.random() * 1) + 3) * 360) + (Math.floor(Math.random() * 28) + 211);
}
duration = 10000; // 10 seconds
// Third spin
} else if (spinCount == totalSpins) {
//get random number of rotations + get random degree for options other than "No Win" and "Free Apple Earpods"
//31 to 119 deg or 151 to 209 deg or 271 to 359
if (Math.random() < 0.7) {
rotation = ((Math.floor(Math.random() * 1) + 5) * 360) + (Math.floor(Math.random() * 88) + 31);
} else if (Math.random() > 0.3 && Math.random() <= 0.7) {
rotation = ((Math.floor(Math.random() * 1) + 5) * 360) + (Math.floor(Math.random() * 58) + 151);
} else {
rotation = ((Math.floor(Math.random() * 1) + 5) * 360) + (Math.floor(Math.random() * 88) + 271);
}
duration = 15000; // 15 seconds
// Spins more than 3
} else {
alert("No more spins left");
container.on("click", null);
return;
}
updateAttempts(spinCount);
updateSpins(totalSpins - spinCount);
//Get selected array element
var degSelected = (rotation % 360) % 360;
if (
(degSelected >= 91 && degSelected <= 120) ||
(degSelected >= 181 && degSelected <= 210) ||
(degSelected >= 331 && degSelected <= 360)
) {
selected = 11;
} else if (
(degSelected >= 1 && degSelected <= 30) ||
(degSelected >= 121 && degSelected <= 150) ||
(degSelected >= 181 && degSelected <= 210) ||
(degSelected >= 211 && degSelected <= 240)
) {
selected = 10;
}else if (
(degSelected >= 31 && degSelected <= 60) ||
(degSelected >= 151 && degSelected <= 180) ||
(degSelected >= 271 && degSelected <= 300)
) {
selected = 9;
}else if (degSelected >= 241 && degSelected <= 270) {
selected = 6;
}else if (
(degSelected >= 61 && degSelected <= 90) ||
(degSelected >= 301 && degSelected <= 330)
) {
selected = 4;
}
vis.transition()
.duration(duration)
.ease(d3.easeExpOut)
.attrTween("transform", rotTween)
.each("end", function () {
//set prize value
prize = data[selected].value;
id = data[selected].id;
if(spinCount == 3) {
alert('Your Voucher: ' + data[selected].label);
}else {
alert('Better luck next time');
}
oldrotation = rotation;
container.on("click", spin);
});
img2.transition()
.duration(duration)
.ease(d3.easeExpOut)
.attrTween("transform", rotTween)
}
You can set the function of #click, based on the state of rotationState as mentioned before:
#click="rotationState ? spin() : null"
Here's how I would write it in C.
if(x < 50 && x < 0.125y)
{
return 0;
}
else if(x < 50 && x >= 0.125y)
{
if(z >= 2a)
{
return 50;
}
}
else return b;
Here's my attempt, it's just a bunch of nested ifs...
IIf(([Est_Order_Qty]<50) And ([Est_Order_Qty]<0.125*[Quantity On Hand]),"0",IIf(([Est_Order_Qty]<50) And ([Est_Order_Qty]>=0.125*[Quantity On Hand]),IIf([Est_Order_Qty]<2*[Qty],"50",[Rounded_To_50])))
IIF((x < 50) AND (x < 0.125 * y), 0,
IIF((x < 50) AND (x >= 0.125 * y) AND (z >= 2 * a), 50,
b)
or with your attempt
IIf(([Est_Order_Qty] < 50) And
([Est_Order_Qty] < 0.125 * [Quantity On Hand]), "0",
IIf(([Est_Order_Qty] < 50) And
([Est_Order_Qty] >= 0.125 * [Quantity On Hand]),
IIf([Est_Order_Qty] < 2 * [Qty], "50", [Rounded_To_50]),
[Rounded_To_50])
)
Try Switch
SWITCH(
x < 50 AND x < 0.125y, 0,
x < 50 AND x >= 0.125y AND z >= 2a, 50,
TRUE, b)
If I understood your if statement correctly, then my answer came out to:
iif(x < 50 And x > 0.125y, "0", iif(x < 50 And x >= 0.125y, iif(2 >= 2a, 50, ""), b))
I believe this is it. Let me know.
Simple question, all I want to do is have Solve[] work in a way that instead of solving for a single variable (eg. Vo) it solves for the expression Vo/Vi. In all cases this just equates to dividing both sides by Vi, as it'll cancel out on the RHS anyway, curious if there's a quick way to do it though.
Thanks
EDIT: Here's the code
vd = 0 - V1;
VL = Solve[(V1 - Vi)/R1 + (V1 - Vo)/R2 == 0, V1][[All, 1, 2]][[1]];
VR = Solve[(Vo - V1)/R2 + (Vo - (AO*vd))/RO == 0, V1][[All, 1, 2]][[1]];
Av = Solve[VL == VR, Vo][[All, 1, 2]][[1]];
Av = Av/Vi //I add this to remove the Vi
Basically I want it to solve for Vo/Vi, to automatically remove the Vi from the RHS...
You seem to be using V1 as a placeholder in Solve to get VL and VR. Let's get rid of V1 by putting VL and VR directly into those equations. This means that we also need to define vd as 0 - VR.
Also, let's define Av as Vo/Vi.
We can stuff all of the equations into Eliminate, asking it to eliminate Vo, Vi, VL, VR, and vd:
In[72]:= Eliminate[
vd == 0 - VR
&& (VL - Vi)/R1 + (VL - Vo)/R2 == 0
&& (Vo - VR)/R2 + (Vo - (AO*vd))/RO == 0
&& VL == VR
&& Av == Vo/Vi,
{Vo, Vi, vd, VL, VR}]
Out[72]= Av (1 + AO + R2/R1 + RO/R1) == (-AO R2 + RO)/R1 && R1 != 0 &&
R2 != 0 && RO != 0
That's pretty close to what we want, but it's not quite solved for Av, so let's do that too:
In[73]:= Solve[
Eliminate[
vd == 0 - VR
&& (VL - Vi)/R1 + (VL - Vo)/R2 == 0
&& (Vo - VR)/R2 + (Vo - (AO*vd))/RO == 0
&& VL == VR
&& Av == Vo/Vi,
{Vo, Vi, vd, VL, VR}],
Av]
Out[73]= {{Av -> (-AO R2 + RO)/(R1 + AO R1 + R2 + RO)}}
If you want to actually define the symbol Av, we can do that using /. (ReplaceAll):
In[80]:= Av =.; Av = Av /. Solve[
Eliminate[
vd == 0 - VR
&& (VL - Vi)/R1 + (VL - Vo)/R2 == 0
&& (Vo - VR)/R2 + (Vo - (AO*vd))/RO == 0
&& VL == VR
&& Av == Vo/Vi,
{Vo, Vi, vd, VL, VR}],
Av][[1]];
In[81]:= Av
Out[81]= (-AO R2 + RO)/(R1 + AO R1 + R2 + RO)
I implemented a calculator in my app using the method below but it seems to be coming up with errors
- (IBAction)calculate {
float x = ([textField1.text floatValue]);
if (x>=)
{
(x<=14000,x*0.0125);
(x<=30000,175+x-14000*0.015);
(x<=80000,415+x-30000*0.0175);
(x<=300000.1290+x-80000*0.035);
(x<=1000000,8990+x-300000*0.045);
(x<=3000000,40490+x-1000000*0.055);
}
}
I'm guessing here (because what you posted isn't C/C++/ObjC syntax):
- (IBAction)calculate {
float x = ([textField1.text floatValue]);
if (x <= 14000) {
x *= 0.0125;
} else if (x < 30000) {
x = ((x - 14000) * 0.015) + 175;
} else if (x < 80000) {
x = ((x - 30000) * 0.0175) + 415;
} else if (x < 300000) {
x = ((x - 80000) * 0.035) + 1290;
} else if (x < 1000000) {
x = ((x - 300000) * 0.045) + 8990;
} else if (x < 3000000) {
x = ((x - 1000000) * 0.055) + 40490;
}
}