How to add variable on a set (Alloy) - time

module carona
open util/ordering[Time]
sig Time {}
sig Car {
passengers : set Passager
}
one sig UFCG{
students: set Student -> Time
}
abstract sig Student{
region: Region -> Time
}
sig Owner extends Student{
ownerCar : Car
}
sig Passager extends Student{
}
abstract sig Region{ }
one sig Norte,Sul,Leste,Oeste,Centro extends Region{ }
fact Owner{
all o: Owner | #o.ownerCar = 1
}
fact Passager{
all p:Passager | one p.~passengers
}
fact Car{
all c:Car| one c.~ownerCar
all c:Car| #c.passengers <= 4
all c:Car| c.passengers.region=(c.~ownerCar).region
}
fact UFCG {
all passager: Passager, ufcg : UFCG, t:Time | passager in (ufcg.students).t
all owner: Owner, ufcg: UFCG,t:Time | owner in (ufcg.students).t
}
fact Traces{
init[first]
all pre: Time-last | let pos = pre.next |
lone u:UFCG|
some s:Student|
addStudent[s,u,pre,pos]
}
pred init[t:Time]{
one u:UFCG | no (u.students).t
}
pred addStudent[s:Student, u: UFCG, before, after: Time]{
(s !in (u.students).before)
(u.students).after = (u.students).before + s
}
After I run and show the instances created over time, my pred to add Passenger doesn't seem to work, nothing changes or even create. How do i properly add items on a set?
My program, when run, does not show any instance. That is, I can not add anything over time.

Well, for one thing, in the UFCG fact the first quantified formula says that at every time every passenger is in the UFCG student set, this preventing any change in that set.

Related

Editing the get_string function in Game Maker Studio 2

Everything works yet when I get prompted up to enter my name it looks like an error. Is there anyway I can edit it?
I am new to GameMaker, this is just my personal work for fun.
I have been looking online for a solution but it does not seem to be anywhere, I not sure if it's possible.
The following is the code that I am referring to.
if (currentHealth <= 0) {
name = get_string("Please enter your name: ","Anonymus");
highscore_add(name, global.points);
room_goto(GAMEOVER);
}
Maybe try "get_string_async()"
get_string should only be used for debugging. if you use get_string_async() your code will look like this
Create Event:
async = -1
input = 0
Step Event:
if (currentHealth <= 0 && input == 0) {
name = get_string_async("Please enter your name: ","Anonymus");
input = 1
}
Async_Dialogue Event:
var i_d = ds_map_find_value(async_load, "id");
if i_d == async
{
if ds_map_find_value(async_load, "status")
{
name = ds_map_find_value(async_load, "result");
highscore_add(name, global.points);
room_goto(GAMEOVER);
}
This works fine for me
If you want an "input field" (term to look for), you can use keyboard_string. For example,
Create:
keyboard_string = "";
Step:
if (keyboard_check_pressed(vk_enter)) {
input = keyboard_string;
// ... do something with `input`
}
Draw:
draw_text(x, y, keyboard_string);
Or a slightly less basic example that I made in 2013.

Set current time in init ELM 0.19

I get input JSON data from JS. This is a simple object, among which there is a date in the format "DD.MM.YYYY" - just a string.
If there is no dateStart in the object, I have to replace it with the current date (in withDefault).
paramsDecoder : Decode.Decoder Params
paramsDecoer =
Decode.succeed Params
|> Decode.andMap (Decode.field "dateStart" (Decode.string) |> (Decode.withDefault) "")
|> Decode.andMap (Decode.field "dateEnd" (Decode.string) |> (Decode.withDefault) "")
|> Decode.andMap (Decode.field "country" (Decode.string) |> (Decode.withDefault) "spain")
How can I do this in ELM?
Timezone is not important and is always equal to the same region.
I found an example of Time.now Time.zone usage,
but there time is getting in Update and its too late.
I solved this in two parts:
Part 1
Send the current time in to Elm when it initializes, using flags:
Elm.Main.init({flags: Date.now()});
And put it in your model:
import Time exposing (Posix, millisToPosix)
type alias Model = { now : Time.Posix, ... }
init : Int -> (Model, Cmd Msg)
init time = (Model (millisToPosix time), Cmd.none)
For your use case, you can then use withDefault model.now.
Part 2
The solution in Part 1 will only set now to the time when the page is loaded.
If you want to keep an up to date time you can use Time.every to update your model:
import Time exposing (Posix, millisToPosix, every)
timeOutCheck : Sub Msg
timeOutCheck = Time.every 250 UpdateTimeNow
type Msg = UpdateTimeNow Posix | ...
update msg model = case msg of
UpdateTimeNow time = { model | now = time }
...
This will ensure now is never more than 250 ms behind the current time. You can change 250 to suit your need.

F# Type Provider slows down intellisense in Visual Studio 2017

I have a very simple type provider; all types are erased, the provided type has 2000 int readonly properties Tag1..Tag2000
let ns = "MyNamespace"
let asm = Assembly.GetExecutingAssembly()
let private newProperty t name getter isStatic = ProvidedProperty(name, t, getter, isStatic = isStatic)
let private newStaticProperty t name getter = newProperty t name (fun _ -> getter) true
let private newInstanceProperty t name getter = newProperty t name (fun _ -> getter) false
let private addStaticProperty t name getter (``type``:ProvidedTypeDefinition) = ``type``.AddMember (newStaticProperty t name getter); ``type``
let private addInstanceProperty t name getter (``type``:ProvidedTypeDefinition) = ``type``.AddMember (newInstanceProperty t name getter); ``type``
[<TypeProvider>]
type TypeProvider(config : TypeProviderConfig) as this =
inherit TypeProviderForNamespaces(config)
let provider = ProvidedTypeDefinition(asm, ns, "Provider", Some typeof<obj>, hideObjectMethods = true)
let tags = ProvidedTypeDefinition(asm, ns, "Tags", Some typeof<obj>, hideObjectMethods = true)
do [1..2000] |> Seq.iter (fun i -> addInstanceProperty typeof<int> (sprintf "Tag%d" i) <## i ##> tags |> ignore)
do provider.DefineStaticParameters([ProvidedStaticParameter("Host", typeof<string>)], fun name args ->
let provided = ProvidedTypeDefinition(asm, ns, name, Some typeof<obj>, hideObjectMethods = true)
addStaticProperty tags "Tags" <## obj() ##> provided |> ignore
provided
)
do this.AddNamespace(ns, [provider; tags])
Then a test project with two modules in separate files:
module Common
open MyNamespace
type Provided = Provider<"">
let providedTags = Provided.Tags
type LocalTags() =
member this.Tag1 with get() : int = 1
member this.Tag2 with get() : int = 2
.
.
member this.Tag1999 with get() : int = 1999
member this.Tag2000 with get() : int = 2000
let localTags = LocalTags()
module Tests
open Common
open Xunit
[<Fact>]
let ProvidedTagsTest () =
Assert.Equal<int>(providedTags.Tag1001, 1001)
[<Fact>]
let LocalTagsTest () =
Assert.Equal<int>(localTags.Tag100, 100)
Everything works as expected (tests execution included). The problem I have is with the design time behavior inside Visual Studio, while I write code. I expect to have some overhead due to the type provider, but the slowness seems frankly excessive. The times reported below are in seconds and refer to the time measured from pushing the dot (.) key until the intellisense property list appears on the screen
providedTags. -> 15
localTags. -> 5
If I comment out or remove the first test code lines (so to eliminate any references to the provided stuff), then I get
localTags. -> immediate
If the number of properties is greater, the time seems to increase exponentially, not linearly, so that at 10000 it becomes minutes.
Questions are:
Is this normal or am I doing something wrong?
Are there guidelines to achieve a faster response?
If someone is curious about why I need so many properties, I am trying to supply an instrument to data analysts so that they can write F# scripts and get data out of an historian database with more than 10000 tags in its schema.
Issue has been fixed by Don Syme, see
https://github.com/fsprojects/FSharp.TypeProviders.SDK/issues/220
and
https://github.com/fsprojects/FSharp.TypeProviders.SDK/pull/229

Alloy metamodel :: define local state and global state

We need to create a metamodel of Alloy models. We have some doubts about how to model global and local state inside our model. We have this model so far:
open util/ordering[Estado] as E
sig Estado{
}
//an alloy model is composed by a set of signatures
sig Model {
sigs : set Signature
}
// each signature has name
sig Signature {
nameSig : one Name
}
sig Name {
}
sig Atom {
nameAtom : one Name
}
sig Instance {
atom : set Atom -> Estado,
instance : set Estado
}
pred solve [m : Model, i : Instance, e : Estado] {
-- every signature name must be different and they all should be part of the signatures
(i.atom.e).(nameAtom) in (m.sigs).(nameSig)
}
pred valid[m : Model] {
all n : Name | lone nameSig.n & m.sigs
}
pred invs [e : Estado]{
-- every sig make part of the model
all s : Signature | s in Model.sigs
all m : Model | valid[m]
all m : Model, i : Instance | solve[m, i, e]
all a : Atom | a in (Instance.atom).e
}
-- invariants
fact invs1 {
all e : Estado | invs[e]
}
----------------------------------------------------------------------------------
-- Será que estes predicados são sobre os atomos ou sobre as instancias?
----------------------------------------------------------------------------------
--pred mantemAtoms[e,e' : Estado, i : Instance]{
-- i.atom.e' = i.atom.e
--}
-- run { some e,e' : Estado, i : Instance | mantemAtoms[e, e', i] } for 3 but exactly 1 Model, exactly 2 Estado
--check addAtoms {
--all e,e' : Estado, a : Atom, i : Instance | invs[e] and addAtoms[e, e', a, i] => invs[e']
--}
pred addAtoms[e,e':Estado, a : Atom, i : Instance]{
--pre
a not in i.(atom.e)
--pos
atom.e' = atom.e + i -> a
instance.e' = instance.e + i
--frame
}
run { some e,e' : Estado, i : Instance, a : Atom | addAtoms[e, e', a, i] }
for 3 but exactly 1 Model, exactly 2 Estado
--check addAtoms {
--all e,e' : Estado, a : Atom, i : Instance | invs[e] and addAtoms[e, e', a, i] => invs[e']
--}
pred excludeAtoms[e,e' : Estado, i : Instance]{
--pre
i in instance.e
--pos
atom.e'= atom.e - i -> i.(atom.e)
instance.e' = instance.e - i
--frame
}
The question is how to model the local and global state inside such a model? We know what are the differences and how to model each state in a specific model but this is different.
Since you are interested in metamodelling, i.e. modelling Alloy models themselves, the Model signature encodes one particular model and the state associated with it can directly represent the global state (i.e. global state can be modelled as state associated with an instance of Model). Local state, in turn, can be associated with instances of Signature signature (which are in turn associated with a particular instance of Model). Effectively, this approach can be thought of as viewing models "one level" higher, where a model is not a top-level entity but an instance of a signature. (The question is quite general and vague -- I hope my understanding of the question was appropriate and this answers the question.)

How can I create a Bacon.Property representing a property in a referenced object?

I have started playing with Bacon.js, and I have come across a problem I can't find any example for.
I have a set of nodes, which may reference other nodes.
It looks like this in imperative code:
alice = { name: "Alice" }
bob = { name: "Bob" }
carol = { name: "Carol" }
alice.likes = bob
bob.likes = carol
alice.likes.name //=> "Bob"
bob.name = "Bobby"
alice.likes.name //=> "Bobby"
alice.likes = carol
alice.likes.name //=> "Carol"
Now, I would like to have a Property for alice.likes.name, which has to change
whenever alice.likes points to a different object, or the name property of the
current object in alice.likes changes.
I have come up with the code below (LiveScript syntax), which correctly logs 3 messages: Bob, Bobby, Carol.
I'm using Bus for testing purposes.
mkBus = (initialValue) ->
bus = new Bacon.Bus()
property = bus.toProperty(initialValue)
property.push = (newValue) -> bus.push(newValue)
property
alice = { pName: mkBus("Alice"), pLikes: mkBus(null) }
bob = { pName: mkBus("Bob"), pLikes: mkBus(null) }
carol = { pName: mkBus("Carol"), pLikes: mkBus(null) }
alice.pLikes.onValue (person) ->
if person
person.pName.onValue (vName) ->
console.log vName
alice.pLikes.push(bob)
bob.pLikes.push(carol)
# Change name
bob.pName.push("Bobby")
# Change reference
alice.pLikes.push(carol)
Question: How can I make a Property that represents the name of alice.likes.name?
I.e:
nameOfAlicesFavourite.onValue (vName) ->
console.log vName
I'm new to FRP, so let me know if I'm doing something horribly wrong.
Thanks #Bergi for pointing me to flatMap.
flatMap creates a new stream for every event in the source. I used flatMapLatest, so that only the name changes from the latest liked person are transmitted on the output stream.
Here's the code:
nameOfAlicesFavourite = alice.pLikes.flatMapLatest (person) ->
if person
person.pName
else
Bacon.never!

Resources