object oriented – Is there a valid case for two components to depend on each other?

This is just a self-fulfilling prophecy – whenever you find a cyclic dependency A <–> B where neither A nor B can be split up into smaller components, that gives you a striking argument for having A and B to be combined to single component (AB). As long as you argue that way, you obviously cannot come to a different conclusion.

Lets take a real-world example: Microsofts Scripting Runtime. This library contains components “File” and “Folder”. Each File has a parent folder, and each Folder can contain a list of files. So we have indeed a cyclic dependency. Can those two components be split into smaller ones? I guess not without changing the whole semantics. Do they have behaviour? Of course, there are tight to objects in the file system which can be deleted, queried, tested for existence, moved, and so on. Should they be combined into one bigger component? Well, in some sense they are already, they are both part of the FileSystemObject part of the Scripting Runtime, and you cannot reference and use a File or Folder component alone. But now this boils down just to your point of view: on one level of abstraction, these two objects are different components on their own, on another they are not. And you can take this as proof of your hypothesis or a disproof, whatever you like.

Backtracking – How do explicit constraints depend on problem instance in backtracking?

I was reading the Chapter on Backtracking in Fundamentals of Computer Algorithms by Horowitz and Sahani, and I read the following line.

The explicit constraints depend on the particular instance I of the problem being solved.

I don’t understand why this statement is true? I have an understanding that the set S (to which all the elements of the n-tuple belong) would be the same for all instances of the problem, but this statement suggests that it depends on the problem instance.

Python: scalable design of a system with multiple state machines, where valid state transitions depend on the state of other machines

This is a pretty big question, however I would appreciate if you could only review the design and not my implementations. the Implementation and proof Sections could be ignored, they are only there to aid in design description, in case you didn't describe it very well. This makes this question narrower in scope.

I have a system with multiple computers that can be in many states (For example, on, open, in zone 1, etc.). The total number of possible states of the entire system is very large, as there are many systems. I need to design some software to restrict the number of possible states in a subset that has been deemed desirable.

For the sake of this question, I will reduce the complexity of this system so that it only contains two computers that each have only two states, "On" and "Off".

The total number of this indicates that this system can therefore be 4:

#| item 1 | item 2 |
#|   On   |   On   |
#|   On   |   Off  |
#|   Off  |   On   |
#|   Off  |   Off  |

The states that are considered desirable are those in which there is only 1 element at a time. This reduces the number of states to 3 and the state machine is

#                     ,----------------------------,
#                     v                            |
#    ,----------(BothOffState)--------,            |
#    | turnOn1()                      | turnOn2()  |
#    v                                v            |
# (item1_OnState )             (item2_OnState)     |
#        | turnOff1()                | turnOff2()  |
#        `---------------------------'-------------'
#

Create the state machine for the entire system, as shown above. The state machine would contain a state object that represents a valid state that my system can have. The state object would have functions to transition to another valid state that can be reached from this current state. State objects would only have functions to pass states to which it has a valid transition, and each state I create would represent a valid state.

Implementation:

class IState(metaclass=ABCMeta):
     def __init__(self, fsm):
        print("system : " + fsm.currentState.__class__.__name__ + " -> " + self.__class__.__name__)
        self._fsm = fsm

class BothOffState(IState):
    def __init__(self, fsm):
        super().__init__(fsm)

    def turnOn1(self):
        self._fsm.currentState = item1_OnState(self._fsm)

    def turnOn2(self):
        self._fsm.currentState = item2_OnState(self._fsm)

class item1_OnState(IState):
    def __init__(self, fsm):
        super().__init__(fsm)

    def turnOff1(self):
        self._fsm.currentState = BothOffState(self._fsm)

class item2_OnState(IState):
    def __init__(self, fsm):
        super().__init__(fsm)

    def turnOff2(self):
        self._fsm.currentState = BothOffState(self._fsm)

class FSM:
    currentState = None
    def __init__(self):
        self.currentState = BothOffState(self)

Proof:

if __name__ == "__main__":

    system = FSM()
    print("")
    system.currentState.turnOn1()
    #system.currentState.turnOn2() AttributeError because this state transition doesn't exist
    print("")
    system.currentState.turnOff1()
    print("")
    system.currentState.turnOn2()

    #Output:
    #
    # system : NoneType -> BothOffState
    # 
    # system : BothOffState -> item1_OnState
    # 
    # system : item1_OnState -> BothOffState
    # 
    # system : BothOffState -> item2_OnState

Problem with this approach

This seems fine but is not very scalable. If there are 20 elements, and each has an average of 5 states, this would mean creating 3.2 million state objects to represent all possible states of the entire system. Even if half of them are deemed undesirable and therefore not believed, this is still too much to realistically implement.

Instead of using 1 mega state machine for the entire system, create smaller state machines for each element that can interact with each other. Instead of states passing directly to each other, they will move to an intermediate state where they will assess whether it is a valid state transition within the context of the larger system. Failure will return you to the state you entered from, and success would move to the desired state

State machines would now look like this:

#      item1 state machine                   item2 state machine
#
#        (OffState) <--------,                  (OffState) <--------,
#            | turnOn()      |                      | turnOn()      |
#            v         eval()|                      v         eval()| 
#  (EvaluateCanTurnOnState)->|            (EvaluateCanTurnOnState)->|
#            | eval()        |                      | eval()        |
#            v               |                      v               |
#        (OnState)           |                  (OnState)           |
#            | turnOff()     |                      | turnOff()     |
#            '---------------'                      '---------------'
# State machines are linked, as the input to one of the state transitions `eval()` is the other state machine

In this example, the 2 systems have identical states, however the idea still works with heterogeneous systems.

When FSMs are created, they will be given a reference to any other state machines they depend on. The intermediate Eval States will use this reference to decide whether the next state should be the desired state or whether to return to the previous state.

Implementation:

class IState(metaclass=ABCMeta):
     def __init__(self, fsm):
        print(fsm.name + " : " + fsm.currentState.__class__.__name__ + " -> " + self.__class__.__name__)
        self._fsm = fsm

class OffState(IState):
    def __init__(self, fsm):
        super().__init__(fsm)

    def turnOn(self):
        self._fsm.currentState = EvaluateCanTurnOnState(self._fsm)
        self._fsm.currentState.eval(self._fsm.otherStateMachine)

class EvaluateCanTurnOnState(IState):
    def __init__(self, fsm):
        super().__init__(fsm)

    def eval(self, otherFsm):
        if otherFsm.currentState.__class__.__name__ == "OffState":
            self._fsm.currentState = OnState(self._fsm)
        else:
            self._fsm.currentState = OffState(self._fsm)

class OnState(IState):
    def __init__(self, fsm):
        super().__init__(fsm)

    def turnOff(self):
        self._fsm.currentState = OffState(self._fsm)

class FSM:
    currentState = None
    otherStateMachine = None

    def __init__(self, name):
        self.name = name
        self.currentState = OffState(self)

    def setOther(self, otherStateMachine):
        self.otherStateMachine = otherStateMachine

Proof:

if __name__ == "__main__":

    fsm1 = FSM("item1")
    fsm2 = FSM("item2")
    fsm1.setOther(fsm2)
    fsm2.setOther(fsm1)

    fsm1.currentState.turnOn()
    fsm2.currentState.turnOn()
    fsm1.currentState.turnOff()
    fsm2.currentState.turnOn()

    #Output:
    #
    # item1 : NoneType -> OffState
    # item2 : NoneType -> OffState
    # item1 : OffState -> EvaluateCanTurnOnState
    # item1 : EvaluateCanTurnOnState -> OnState
    # item2 : OffState -> EvaluateCanTurnOnState
    # item2 : EvaluateCanTurnOnState -> OffState
    # item1 : OnState -> OffState
    # item2 : OffState -> EvaluateCanTurnOnState
    # item2 : EvaluateCanTurnOnState -> OnState

The second approach seems more scalable, since the states of the entire system do not have to be explicitly defined. Dependencies between each state machine are captured during object construction, and if the number of dependent machines increases, this could be fixed with a generator object.

However, I've never seen this design before (because I really don't know where to look). I don't know if the complexity of this will be really impossible to maintain or error prone.

Surely this is a common problem and has it already been solved? What is the standard design to use in a situation like this? If there is no standard design pattern, do you think the design I have suggested is a good design?

Thank you.

dg. differential geometry: let $ M ^ n $ be a closed variety with $ H_ {dR} ^ p (M) neq 0 $. Generically, for any Riemannian metric $ g $, $ K _ { max} / K _ { min} $ does not depend on $ p $?

Leave $ M ^ n $ be a closed variety in such a way that $ H_ {dR} ^ p (M) neq 0 $. Is it true that generically, for any Riemannian metric? $ g $ in $ M $, if one denotes by $ K $ its sectional curvature, then
$ K _ { max} / K _ { min} $ does not depend on $ p $?

Note that this is a less restrictive question than asking what $ K _ { max} / K_ {min} $ It does not depend on the dimension, I also do not know the conditions for this to happen.

How do you approach functional design and how does it depend on the type of project?

How do you approach functional design and how does it depend on the type of project (web front-end, back-end services, embedded, applications, others)? How does it depend on the particular language you are using?

port forwarding: why am I having trouble connecting to my service remotely via public IP (seems to depend on service / listening protocol)?

I am trying to configure port forwarding rules for a couple of different services so that I can connect to them remotely, but I am having some difficulties. I've tried different services / scenarios and can't explain the results, so I'll list some of them and hope it can help determine what's going on.

The router is a NetGear R6260

Two port forwarding rules are configured on the router:

  1. External port 8000 -> Local machine port 8000
  2. External port 4444 -> Local machine port 4444

Here are the results of some of the tests I have tried. All made using public ip.

Netcat listener running on my local machine on port 4444 (nc -lvnp 4444):

Custom python socket script listening on port 4444:

  • CanYouSeeMe.org – Successful connection
  • Telnet from outside lan – Does not connect
  • Telnet of inside lan – Successful connection
  • Netcat from outside lan – Does not connect
  • Netcat's inside lan – Successful connection
  • From web browser outside lan: unable to connect
  • From the web browser within lan – Connection successful

NodeJs web server hosting web application on port 8000:

  • All connections in and out of lan – Successful. Able to view the web application from the browser on and off LAN AND can connect to network services like netcat / telnet

Port forwarding is configured exactly the same for both ports. Port 4444 is discoverable according to CanYouSeeMe.org, But I have only been successful connecting to any listening service on this port from within the network! What the hell is going on? This is very frustrating. Just to reiterate, I am using public ip for each test

Is it strange that liberals depend entirely on conservatives, but conservatives don't need anything from liberals?

This is simply false. I guess you are talking economically. The main way in which liberals depend on conservatives is through agriculture. The country's agricultural regions are generally more conservative, even within states that are largely liberal, such as California or New York. On the other hand, conservatives depend on liberals for almost everything else. All the economic engines of a country are concentrated in the liberal areas. In addition, conservative states tend to be net when it comes to public assistance, and liberal states tend to be net losers. What this means is that liberal states are much more likely to get less money from the federal government than they send it, while conservative states are much more likely to get more money from the federal government than they send it.

Why does the PHP community always depend on file-based registration rather than a combination with memory registration?

This is an initial thought that I am having when logging in. Clearly, I am missing something about the whole image because I don't think anyone has thought about this before.

PHP runs on a request. That means it is contained, which means that each request must open its own connections, etc. This is something given, but when you observe how the registration is done, it is annoying: every time an error occurs, open a file and add it. file and close it, or, as far as I understand, you can open a sequence of files, but that is still written to the system every time the record occurs.

So … why don't we keep all errors in memory? Then, when the request ends (each frame under the sun has actions, which means it can be hooked at the end of a request), do we simply write these to the file?

Naturally, this has an extreme case where the request / system for some reason broke down critically and the writing could not happen, but, assuming it was not a concern, why not simply write in memory and then in the file?

Does the internal structure of a red-black tree depend on the order of insertion?

Does the internal structure of a red-black tree (which nodes are red or black, the arrangement of the branches, the location of each value …) depends on the order in which the elements were inserted? Or does it just depend on the set of inserted elements, regardless of the order? Do different insertion orders always result in the same tree?

In case the order really matters, is there an algorithm that, given a red-black tree, returns a sequence of elements so that when inserted in that same order it returns a structurally identical tree to the one we started?

blockchain: does the price of the btc depend on the reward?

Hi guys, if you answer this question that I am keeping for months I will be happy.

Does the actual price of bitcoin depend on mining profitability?
So, is mine more profitable when the price is high?
Is it the same with other cryptos?
There is a bitcon tab in github and I heard that Pepole can modify it, so why do they modify it if they can't change the real bitcoin code?