Can i set a fixed cycle time? - time

I have now worked a while with Siemens PLC's and i liked it overall.
But something bothered me:
I never found a way to properly set the cycle time of the plc.
For example when i used Codesys there was a field where you can enter your cycle time.
Is it always trying to do it the fastest way possible?

Related

Fair Attraction Algorithm

Fair Attraction Problem
What I've Tried
I tried thinking about the switches as bits of a bit string. Basically, no matter the state, I need to get them all to zero. And since this question is in a chapter about decrease-and-conquer I tried to solve for n=1. But, I can't even come up with a brute force solution to ensure that one switch is off.
If you have any ideas or hints, please help, thank you.
Since the only feedback we get is when we're in the goal state, the problem is to explore all possible states as efficiently as possible. The relevant mathematical object is called a Gray code. Since you're looking for a recursive construction, the algorithm is:
If there are no switches, then there's one state, and we're in it.
Otherwise, pick a switch. Recursively explore all configurations of the other switches. Flip the held-out switch and then recursively explore the others again.

How to detect the offset in a digital signal?

Currently I am writing an algorithm to detect the offset in the values from ADC. An example of a typical signal is as shown in the figure below.
There can be a possibility that such a signal can have an offset at any point of time due to the external conditions. An example is as shown in the figure below.
I would like to determine this exact point when an offset is added to the signal.
Approach I have tried:
Calculate the moving average of around 50 values and compare it to the old mean value. If the difference is too large then conclude that there is an offset.
Problem with this approach: It also considers the peak in the signal as the offset which is not really the case.
The offset has to be detected in real time. I am currently coding in C.
I have spent almost a week trying to figure out the solution, but as a last way out I am asking you guys.
This is a known problem in signal processing, known as step detection:
https://en.wikipedia.org/wiki/Step_detection
There are many algorithms to deal with the problem, you will have to do some research and whichever algorithm you decide to go with, you will probably have to do some parameter tweaking before it suits your needs. I would recommend starting with the sliding window algorithm for your needs, a sample implementation of student's t test can be found here, perhaps you can build on that.

Suggest proof of work algorithm that can be used to control the growth of the blockchain

I'm working on a blockchain based identity system. And, since each item will be in the chain forever, consuming space, I'm thinking on adding a proof of work requirement to add items to the chain.
At first I was thinking of bitcoin, since it's a tried and tested way to prove that the work was done, but doing it this way would prevent users from joining in, since bitcoin is not widely adapted yet. Also, in a distributed system, it is not clear who should get the money.
So, I'm looking for a proof of work algorithm, complexity of which can be easily adjusted based on blockchain growth speed, as well as something that would be hard to be re-used. Also, if complexity would had grown since the work has been started, the work should be able to be completed with adjusted complexity without having to be re-done.
Can someone suggest to me something that would work for my purpose, as well as would be resistant to GPU acceleration?
Simple... burn bitcoins. Anyone can do it - so there's no barrier to entry, and really what you need is "proof of destroyed value". Because the value is destroyed, you know the miner's incentives are to strengthen your chain.
Invent a bitcoin address that cannot be real, but checksums correctly. Then have your miners send to that burn address, with a public key in OP-return. Doing so earns them the right to mine during some narrow window of time.
"Difficulty" is adjusted by increasing the amount of bitcoins burned. Multiple burns in the same window can get reward shared, but only one block is elected correct (that with a checksum closest to the checksum of all of the valid burns for the window).

Algorithm to Calculate "Best" Option Based on Score

I have an essentially infinite set of "challenges", and each one can be solved (or not) using a formula that has a finite set of inputs, each with a finite set of possible values (so that a possible solution to one challenge might be X=10, Y=22, Z=6, and another might be X=3, Y=14, Z=5). Whether or not a challenge is solved by a particular solution is not known until after the formula is applied to the given challenge. At that point, I will know if the challenge was solved or not.
There are some extra factors to consider:
1) Each iteration of the formula takes time and costs money, so I can't use "brute force" and just try every combination.
2) Over time, a solution that used to work may stop working, and vice versa.
3) There is usually more than one solution to a given challenge.
4) Different solutions have varying time and cost factors, so in the absence of any prior attempts at solving a particular challenge, there is a "known order" of solutions, sorted by these factors.
Each time a challenge is presented, I have access to a history of the prior attempts at solving prior challenges with identical attributes. So after I see a particular challenge a few times, I know what solution has and hasn't worked in the past.
The objective is to take the results of the past challenges (with identical attributes) and prioritize the available solutions in the order that they are most likely to succeed. In a highly simplified version of this: If solution 10/22/6 worked 3 of the last 5 times (and no other previously-attempted solutions worked more than 2 times), then solution 10/22/6 is probably the best one to try first; etc.
PS - I'm not expecting anyone to "write this" for me; just hoping for some ideas as to what to explore and experiment with. I can't imagine something like this hasn't been done before.

What algorithm can I implement to speed up some Cellular Automata simulations?

I am writing a ncurses based C.A. simulator for (nearly) any kind of C.A. which uses the Moore or Neumann neighborhoods.
With the current (hardcoded and most obvious [running state funcs]) the simulation runs pretty well; until the screen is filled with 'on' (or whatever active) cells.
So my question is:
Are there any efficient algorithms for handling at least life-like rules?
or Generations, Weighted life/generations...
Thanks.
it's generally nice to only run update passes in areas of the grid that had activity in the previous time step. if you keep a boolean lattice of "did i change this time?" for each pass, you only need to update cells within one radius of those with an "on" in the change lattice.
I think writing state machines is not as much algorhitms designing problem as is just problem how to write clean and "bug free" code. What are you probably looking for is implementation of cellular automata / state chart.
http://www.state-machine.com/ //<- no this is not coincidence
http://www.boost.org/doc/libs/1_40_0/libs/statechart/doc/index.html
You might also try whit stackless python http://stackless.com/. It can be used for state machines or CA. Here http://members.verizon.net/olsongt/stackless/why_stackless.html#the-factory it is tutorial for stackless implementing factory process simulation
You could look into the HashLife algorithm and try to adapt its concept to whatever automata you are working on.

Resources