Predefined Set in Alloy - alloy

I am trying to learn alloy spec. lang. . I can not find a way out about a question.
My question is related with predefined number of elements.
theater_seat set should have 4 members.
Audience set should have 10 members.
There is a theater which is 4 seats available only. But there are 10 people who want to watch the theater. Only 4 of them can have the seat. The rest will go home back.
I am in trouble.
Could you help me about that please?
Thanks in advance.
EDIT
Here is my code :
module Example
sig Audiance{
result: lone Seat
}
some sig Seat {}
pred validassignment {
'#'Seat=4
'#'Audiance=10
all a:Audiance | lone a.result
}
run validassignment
EDIT
How can I eliminate that problem? (Seating on the same seat)
Regards

You might want to show us what you already did, and pinpoint to where you are stuck exactly.
A vague answer to that vague question would be : think "declaratively".
EDIT
Here it doesn't work for two reasons:
First, what you wrote is syntactically wrong. The cardinality operator is # and not '#'.
(I redirect you to there : http://www.monperrus.net/martin/alloy-quick-ref.pdf for a nice overview of the main concepts and associated syntax in Alloy)
Then, the default scope when you run a command is 3. Meaning each set defined by a signature will have a cardinality of at most 3.
You need thus in your case to increase your scope in order to find relevant instances.
You can specify the number of seats and audiances directly in the scope, as follows :
run validassignment for exactly 4 Seat, exactly 10 Audiance
There are still other issues in your model. In its current state, it is possible to have everybody in the audience seating on the same seat. I guess you don't want that to happen.
Good luck

Related

How to define the delay time based on the source?

i'm new using AnyLogic and i don't have many knowledge of programmation, i think that is important to make that clear. I did another question early but i think that i dont explain it very well. So, now i wanna try to do that:
Ok, i need to do a model about an access control, and here is the thing: my process has two delays 1. revision of the car/bus/trailer. 2. registration, but, the time of delay in the revision process is different depending on the type of the car, e.g. to revise the car the security guard expend 2 minutes, and to revise the trailer expend 10 minutes. I want to make it clear that difference in the delay block, because i want to my model look like this: AnyLogic Model
The problem is that i don't know how to do that, i tried to do different things that i read on this foro but i had many problems. If everyone here can help me to do that in a easy way i'll be very grateful.
Depends how you differentiate your agents. Assume there is a boolean parameter isCar in your agent type:
Then, in the delay block's "delay time" code, you can simply write agent.isCar ? 2 : 10
If you have different agent types Car and Trailer flowing through the delay block, you would need to write agent instanceof Car ? 2 : 10
But you need to understand a lot more of the basics. Do the tutorials, study MANY of the example models to get a feel for how to do things. Learn OOP, Java and read this article to understand what agent means above.

'Or' not working with strings in if conditional after user input

So, I'm a noob, and after 2 hours of searching online, I can't find an example of my failed code ANYWHERE, nor can I find answers related to my specific dilemma, which is surprising since it seems like it would be a fairly common conceptual mistake.
Here's my code:
name = input('Who are you?')
if name == "Mike" or "mike":
print('Hi',name,', nice to see you!')
else:
print("I don't know you.")
All I want the program to do is print the 'Hi', name... statement if the user inputs Mike or mike. I'm not wanting to just change the case, but in the future I'd like to use 'Mike' or 'Susie' (or something like that).
Right now it's always printing the 'Hi', name... statement no matter what I input. If I delete one of the names, then it works.
Can someone tell me:
a) Why it doesn't work the way I tried coding this, and
b) What would be the easiest and/or most efficient way to code this, especially if I want to increase the number of inputs that are accepted?
Thanks all,
You did not give a programming language, but your problem is universal across all languages.
You are trying to cram a colloqial sentence into computer logic and it fails. The computer does not understand your human shortcuts, it needs it spelled out:
This is what you would say to another human:
if they are Mike OR Susie
This is what you mean by that:
if their name is Mike OR their name is Susie
And this is exactly what you need to tell the computer:
if name == "Mike" OR name == "Susie"
Please note that a good language/IDE combination with a good confiuration will throw you a lot of warnings and errors when you compile, it won't even let you run your colloqial human logic. If yours does not, you need to tune it up to assist you better and if it cannot be tuned up, you may want to think about using a better IDE or a better language in general.

Clarify different behaviour of neo4j and neo4j-driver

I have a rudimentary database that has just a couple of nodes and relationships. When I run a match (n) return n command on the local web client provided with neo4j it returns all the nodes and relationships that's in the database, as seen in the picture below.
However when I run exactly the same command in a node.js project using the neo4j-driver module, it only returns the three nodes and none of the two relationships are included.
After a little bit of fiddling with it, I noticed that to retrieve the relationships too, I must issue something like match (n)-[r]-(m) return *. My first question is why is there such a difference? Is the local web client just trying to do a bit more to help the user?
Furthermore I find the returned records object a little bit confusing. Running this match (n)-[r]-(m) return * command returns 4 items in the result.records object out of which 2-2 are almost identical pair-wise. In a simplified view this is what it returns:
item 0: [Jack node, Jill node, Jack -> Jill relationship]
item 1: [Jill node, Jack node, Jack -> Jill relationship]
item 2: [George node, Jill node, George -> Jill relationship]
item 3: [Jill node, George node, George -> Jill relationship]
So items 0 and 1 of the result.records object differ only by the order of their elements. Same for items 2 and 3.
Question two is what am I supposed to do with this if I want to display the graph on a web page? Look for unique IDs of the nodes and relationships in all the different combinations returned?
Question three: maybe there's a better way to achieve what I'm trying to do?
The Neo4j web browser is indeed just trying to be helpful and the visualization will connect nodes if they have relationships between them (there's an option to turn this behaviour off btw). However, the resultset will not contain those if you didn't ask for them (as it shouldn't). Look on the other reponse tabs (table, text, code) in the browser to see the actual resultset.
This query may help you :
match p=(n)-[r]-(m) return p
But yes, you are correct, you will have to unpack the result in your application in order to be able to do your own interpretation. It is a case of the you get what you asked for problem that quite a few Neo4j users face. It is due to the fact that Cypher can return quite a few different things (tabular results, nodes, nodes and relationships, paths, subgraphs, ...) and the driver has to provide for all of them.
Have a look at the code tab in the browser to get a feel of what your application will have to work with (what you actually get depends on your application language of choice). It's not very difficult but it does require a bit of getting used to.
Hope this helps.
Regards, Tom
P.S. Doubles in the results are to be expected with such generic queries. Neo4j does pattern matching and your pattern does not have a direction on the relationship nor does it have labels or relationshiptypes. That's going to return quite a few matches where for example (jill)-[:nominated]-(jack) but obviously it also matches (jack)-[:nominated]-(jill). Both match the pattern. Using DISTINCT may help a bit but you really should be more explicit in the pattern.

UML Modelling Qustion

I am in the process of developing some Use Cases for a mobile mapping/gps app. Users will be able to use this app similar to google maps. I was wondering if anyone had valuable input into some possible use cases.
Here are some I came up with myself:
1) Get Current Location
2) Set Destination Location
3) Create Fastest Route
4) View Alternative Routes
5) Traffic Estimation on Routes
If someone could help me elaborate or comment on my direction that would be helpful!
My first impulse was to flag your question as "too broad", as you basically ask to help you with your requirements analysis. But I give a few hints.
Your 5 use cases don't look bad. But they appear to be just a first rough sketch of the functionality of your app, that needs to be refined. A good model, be it UML or anything else, must be helpful for its reader to gain some insight. Now these 5 use cases could be named by any child who has seen a navigation device once in her life. To be meaningful, questions like the following should be asked and will probably lead to a more detailed use case analysis:
How are destination locations selected? If there is more than one place called Jacksonville, how will the user be informed, and how will she select the right one? Does selecting the location consist of more than one step, say country - city - road - block, to assist the user?
How do map data get into the application?
What kind of alternative routes are considered and how should they be calculated?
How will traffic data get into the application?
Try to put yourself into the developer's position. Which questions will she need to have clarified to build the right application?

Patterns for the overlap of two objects

I'm sure this has already been asked and answered so I apologize in advance for that but I'm not figuring out the correct keywords to search for. Searching for "Pattern" hits way too many Q & A's to be useful.
I'm working on a regression testing app. I'm displaying a form on the screen and according to which user is logged in to the app some of the fields should be read-only. So I can abstract a field object and I can abstract a user object but what pattern should I be looking at to describe the intersection of these two concepts? In other words how should I describe that for Field 1 and User A, the field should be read-only? It seems like read-only (or not) should be a property of the Field class but as I said, it depends on which user is looking at the form. I've considered a simple two-dimensional array (e. g. ReadOnly[Field,User] = True) but I want to make sure I've picked the most effective structure to represent this.
Are there any software design patterns regarding this kind of data structure? Am I overcomplicating things--would a two-dimensional array be the best way to go here? As I said if this has been asked and answered, I do apologize. I did search here and didn't find anything and a Google search failed to turn up anything either.
Table driven designs can be effective.
Steve Maguire had few nice examples in Writing Solid Code .
They are also a great way to capture tests, see fit .
In your case something like:
Field1ReadonlyRules = {
'user class 1' : True,
'user class 2' : False
}
field1.readOnly = Field1ReadonlyRules[ someUser.userClass ]
As an aside you probably want to model both users and user classes/roles/groups instead of combining them.
A user typically captures who (authentication) while groups/roles capture what (permissions, capabilities)
At first blush it sounds more like you have two different types of users and they have different access levels. This could be solved by inheritance (PowerUser, User) or by containing a security object or token that sets the level for the user.
If you don't like inheritance as a rule, you could use a State pattern on the application, Decorate the user objects (Shudder) or possibly add strategy patterns for differing security levels. But I think it's a little early yet, I don't normally apply patterns until I have a firm idea of how the item will grown and be maintained.

Resources