Where do I specify that certain planning entities are immutable? - drools

I am making a (2X2) Sudoku game and I need to complete a puzzle. That means that some digits are immutable (they cannot be moved out of place.
In a 2X2 game, there are 16 Digits. The problem facts are rows, columns and blocks (get it?). The row is the only planning variable.
I specified boolean fixed as attribute for Digit. But (as per the user guide), I found no place to implement it.
What are the ways to actually make some planning entities immutable?
I find these methods:
Implement a moveFactory that changes the row only if it is immutable. This method is not documented.
If the row is not equal to a fixed_row, break a hard constraint.
Use #ValueRangeFromPlanningProperty. Let the immutable entities have a value_range of a single element, and the mutable entities have have a list that excludes the fixed rows. This seems unsustainable for anything larger than a Sudoku project, right? And there are (my?) alleged pitfalls that derail the solver?
Extra question: is method #3 the recommended way for something like a timetabling problem (allocate subject-teacher to a possible period)?

Option 4:
The fixed digits are problem facts: instances of a class that does not have a #PlanningEntity annotation.
The non-fixed digits are planning entities: instances of a class that does have a #PlanningEntity.
If you'd like to reuse the same class for both for design purposes:
A custom MoveFactory would be the way. Writing a custom move factory is documented: it's just a matter adding an if statement to excluding moves that change a fixed digit.
In that case it's not a build-in hard constraint but a normal hard constraint, I wouldn't recommend that for this use case. See manual info about "build-in hard constraints"
Overkill, but it would work :)
Option 5: https://issues.jboss.org/browse/JBRULES-3359

Related

Polymorphism in sysml

currently i am trying to design an executable activity where a logical component send a request to several other logical components to start initialization. The usual way in activity diagram is to create for each block a swimline. But, as the number of LCs are high in this case the diagram will be extremely big and also later its modification will be a hurdle.
In programming, the solution to this problem is polymorphism where the objects are casted as the mother class and pushed into a vector and then within the loop the abstract function of the mother class is called.
I wonder if there is any similar solution to this problem in sysml or not?
I tried to assign one swimline to the all the LCs which recevie the request but it seems each swimline can only be assigned to a block.
Yes, there is a similar solution. Actually, it is even easier. Just let the ActivtyPartition represent a property with a multiplicity greater than 1. Any InvocationAction in this partition will then mean a concurrent invocation on all instances held in this property.
The UML specification says about this:
section 15.6.3.1 Activity Partitions
If the Property holds more than one value, the
invocations are treated as if they were made concurrently on each
value and the invocation does not complete until all the concurrent
instances of it complete.
Typical InvocationActions are CallActions and SendSignalActions. So, you could call the initialize() operation in a partition representing the property myLogicalComponents:LC[1..*].
If you don't already have defined such a property, you can derive it, by making it a derived union and then define all existing properties with components to be initialized as subsets of it:
/myLogicalComponents:LC[1..*]{union}
LC1:LC {subsets myLogicalComponents}
LC2:LC {subsets myLogicalComponents}
Of course, this assumes, that all your logical components are specializing LC, so that they all inherit and redefine the initialize() operation.
In SysML you also have AllocateActivityPartitions. No clear semantics is described for it, so I think you are better served with the UML ActivityPartitions, which are also included in SysML.

Converting binary to decimal within a case structure in LabVIEW 2018

I have two CONTROLs (buttons specifically) that when activated act as one bit each.
So it basically means the highest number I can produce is 2 by having both buttons activated at the same time. EDIT: Okay what I meant to say was that the highest output I'm going to be able to produce is two because I only have 2 buttons, each representing a 1. So 1+1=2.
However, this is only understood logically because the bits are yet to be converted to a numerical(decimal) format. I can use a 'Boolean to 0,1' converted directly to get the values but I'm instructed to use a case structure to complete this.
Right now I'm completely perplexed because a case structure needs exactly ONE case selector but I have TWO buttons. Secondly, this problem seems way too SIMPLE to require a case structure therefore making it genuinely harder to use a more complex method.
So it basically means the highest number I can produce is 2 by having both buttons activated at the same time.
A 2bit-number can have four values, 0...3, hmm?
In general, if the two booleans are bits of the number, or the number can somehow be calculated from the bools, do it.
But if the number can have predefined values which depend on the booleans, but can not be calculated from them, you need some other kind of case distinction. Maybe, whoever instructed you, had this in mind.
You can make a case structure for the first boolean, and in each case, insert a second case structure for the second boolean. This is good when there will be more complex code and logic depending on the boolenans, so you can easily concentrate on one combination of values. For simple cases, this lacks overview, and when adding a third boolean, it's lots of work.
Calculate an interim value, and connect it to a single case structure. Now, there is only one case structure, but you have no overview over all cases. Note I've changed the radix of the case struture to boolean, so you can see the bits in the selector.
Use a simple array to take a value from
Create a lookup table with predefined conditions and values
(Note that the first two solutions force you to implement each case, while the last two do not - what if your arrays are of size 3, only?)

Drools 6 Fusion Notification

We are working in a very complex solution using drools 6 (Fusion) and I would like your opinion about best way to read Objects created during the correlation results over time.
My first basic approach was to read Working Memory every certain time, looking for new objects and reporting them to external Service (REST).
AgendaEventListener does not seems to be the "best" approach beacuse I dont care about most of the objects being inserted in working memory, so maybe, best approach would be to inject particular "object" in some sort of service inside DRL. Is this a good approach?
You have quite a lot of options. In decreasing order of my preference:
AgendaEventListener is probably the solution requiring the smallest amount of LOC. It might be useful for other tasks as well; all you have on the negative side is one additional method call and a class test per inserted fact. Peanuts.
You can wrap the insert macro in a DRL function and collect inserted fact of class X in a global List. The problem you have here is that you'll have to pass the KieContext as a second parameter to the function call.
If the creation of a class X object is inevitably linked with its insertion into WM, you could add the registry of new objects into a static List inside class X, to be done in a factory method (or the constructor).
I'm putting your "basic approach" last because it requires much more cycles than the listener (#1) and tons of overhead for maintaining the set of X objects that have already been put to REST.

Object Oriented Design of a parking lot

While studying for Interviews, this question came to my mind.
I am planning to design a parking lot and I am assuming the following things:
It has multiple levels. Each Level has 2 rows.
The vehicle type could be small, compact and large.
Each row at a certain level has multiple parking spots.
Each parking spot has red/green light indicator( Red- No space, Green- Free space)
Also each parking spot will have size small, compact and large.
6(optional). Also want to add handicapped person situation.
These are some of the assumptions that I could come up with(Not sure if they are enough or I need more).
I was thinking of designing the system in such a way that as soon as the Vehicle enters the Parking entrance.
He should be given information that where is the nearest vacant spot available(For example- Level 3, Row 2, Spot # 10)
I would like to know how to go about designing such a system? I have seen many other designs but none achieves this i guess.
Not sure what you want to achieve through point 6, but the rest are pretty simple to achieve with an OO design, through the usual abstraction, inheritance and polymorphism principles.
You can have an interface called AvailabilityIndicator which has a boolean method isAvailable(), which represents the light indicator (the bulb will show red if isAvailable() is false, and green if true).
You can have an abstract class called ParkingSlot, which implements AvailabilityIndicator.
This could have the level, row and spot number in it.
You can have 3 classes LargeParkingSlot, CompactParkingSlot and SmallParkingSlot which extend ParkingSlot. (Not that your functionality actually needs this, unless the different parking slots have different behaviours or data you want to model, but since you mentioned you wanted an OO approach I mentioned it, otherwise a simple slotType parameter in ParkingSlot would do.)
Then its a question of when the vehicle arrives, checking what type of slot it needs and looking up which are the available ones that match. You might want to put them in a Map data structure which maps each slot type to the list of available ones, so that when one is taken it is removed and put in a separate unavailable list, for fast lookup of available slots when a vehicle arrives.

best way of handling self-changing array of information

This question is about handling arrays of information, there's are many ways I could do this, but I would like some input from programmers with more experience, I know what I want to do just not how to organize the information the best way, and objective-C is really making me ponder this, I don't want to get 100 hours into work a decide, oops this wasted the beast way to do this. So here goes:
I have a grid where I'm simulating a playing field, each piece of the grid I call a cell. The cells have around 20 different values each, all integers, nothing fancy. A change to a cell will be either by player input, or occur or by surrounding cells through different algorithms.
The changes to cells will occur once a turn is complete, so it's not real time. Now, I'm not even sure about doing this with a MutableArrays, a plain Array, or just a plain matrix. Arrays are good at keeping such info for one dimension, but I would imagine would become quite cumbersome if you have to address a batch of 10,000 of these cells. On the other hand a simple matrix might not be so elegant, but probably easier to work with.
Any insight would be greatly appreciated.
You have two options here that I see:
1) Use standard containers
Assuming that the playing field is of constant size, then you can create a mutable array of x*y size, and populate it with mutable dictionaries. By giving everything in the second mutable dictionary keys, you can query and set their properties (all objects of course, so wrap ints in NSNumbers etc). For indexing use a macro INDEX_FROM_ROW_COL(row, col) and apply the appropriate code to multiply/add.
2) Create a helper object subclassed from NSObject. It would manage mutable objects as above, but you could load it with functionality specific to your application. You could provide methods that have parameters of "row:" and "col:". Methods that change or set properties of each cell based on some criteria. Personally, I think this is a better idea as you can incapsulate logic here and make the interface to it more high level. It will make it easier to log whats going on too.