Suppose there are 8 pcs and 1 switch, I want to divide three subnets.how to use alloy language program?Can you give an example?
The following models a small network.
sig IP {}
some sig Subnet {
range : some IP
}
abstract sig Node {
ips : some IP
}
sig Router extends Node {
subnets : IP -> lone Subnet
} {
ips = subnets.Subnet
all subnet : Subnet {
lone subnets.subnet
subnets.subnet in subnet.range
}
}
sig PC extends Node {} {
one ips
}
let routes = { disj s1, s2 : Subnet | some r : Router | s1+s2 in r.subnets[IP] }
let subnet[ip] = range.ip
let route[a,b] = subnet[a]->subnet[b] in ^ routes
fact NoOverlappingRanges { all ip : IP | one range.ip }
fact DHCP { all disj a, b : Node | no (a.ips & b.ips) }
fact Reachable { all disj a, b : IP | route[a,b] }
run {
# PC = 8
# Subnet = 3
# Router = 1
} for 12
If you run it:
┌───────────┬────────────┐
│this/Router│subnets │
├───────────┼────┬───────┤
│Router⁰ │IP² │Subnet¹│
│ ├────┼───────┤
│ │IP³ │Subnet⁰│
│ ├────┼───────┤
│ │IP¹¹│Subnet²│
└───────────┴────┴───────┘
┌───────────┬─────┐
│this/Subnet│range│
├───────────┼─────┤
│Subnet⁰ │IP³ │
│ ├─────┤
│ │IP⁴ │
├───────────┼─────┤
│Subnet¹ │IP¹ │
│ ├─────┤
│ │IP² │
│ ├─────┤
│ │IP⁵ │
│ ├─────┤
│ │IP⁶ │
│ ├─────┤
│ │IP⁷ │
│ ├─────┤
│ │IP⁸ │
│ ├─────┤
│ │IP⁹ │
│ ├─────┤
│ │IP¹⁰ │
├───────────┼─────┤
│Subnet² │IP⁰ │
│ ├─────┤
│ │IP¹¹ │
└───────────┴─────┘
┌─────────┬────┐
│this/Node│ips │
├─────────┼────┤
│PC⁰ │IP¹⁰│
├─────────┼────┤
│PC¹ │IP⁹ │
├─────────┼────┤
│PC² │IP⁸ │
├─────────┼────┤
│PC³ │IP⁷ │
├─────────┼────┤
│PC⁴ │IP⁶ │
├─────────┼────┤
│PC⁵ │IP⁵ │
├─────────┼────┤
│PC⁶ │IP⁴ │
├─────────┼────┤
│PC⁷ │IP¹ │
├─────────┼────┤
│Router⁰ │IP² │
│ ├────┤
│ │IP³ │
│ ├────┤
│ │IP¹¹│
└─────────┴────┘
You'd probably like to see what PCs are assigned to what subnet. Then go to the evaluator and type:
ips.~range
┌───────┬───────┐
│PC⁰ │Subnet¹│
├───────┼───────┤
│PC¹ │Subnet¹│
├───────┼───────┤
│PC² │Subnet¹│
├───────┼───────┤
│PC³ │Subnet¹│
├───────┼───────┤
│PC⁴ │Subnet¹│
├───────┼───────┤
│PC⁵ │Subnet¹│
├───────┼───────┤
│PC⁶ │Subnet⁰│
├───────┼───────┤
│PC⁷ │Subnet¹│
├───────┼───────┤
│Router⁰│Subnet⁰│
│ ├───────┤
│ │Subnet¹│
│ ├───────┤
│ │Subnet²│
└───────┴───────┘
Disclaimer: This was quickly hacked together so there might be modeling errors.
Alloy is a modelling language used mainly to reason about designs. So Forget about "programming".
What you can do in Alloy is to define the general rules of how pc, switch and subnets relate to each other. You can then verify if those rules allow to divide those pc into three subnets, and if the division match your expecations. In the case it does not, congrats, you have found a "bug" in your specification, solving it will improve your understanding of the constraints inherent to the system you are currently modelling.
Related
I'm sorry if I miss something but I don't understand why this doesn't work:
using DataFrames, MLJ
julia> df = DataFrame(A = 1:4, B = ["M", "F", "F", "M"])
4×2 DataFrame
│ Row │ A │ B │
│ │ Int64 │ String │
├─────┼───────┼────────┤
│ 1 │ 1 │ M │
│ 2 │ 2 │ F │
│ 3 │ 3 │ F │
│ 4 │ 4 │ M │
julia> hot_model = OneHotEncoder()
julia> hot = machine(hot_model, df)
julia> fit!(hot)
julia> Xt = MLJ.transform(hot, df)
Xt is exacty as df, it didn't tranform the columns.
I tried to specify the features in OneHotEncoder() but it doesn't change.
I also saw that you can make a pipeline with it by wrapping it and fitting only at the end with the model but it should work like that, no? Is it maybe because of the type of the columns? What scitype should it be? Categorical? How can I change it into that?
Yes, you will need to change the scitypes of the columns. You can check the scitype of each column by using schema on the data frame:
julia> schema(df)
┌─────────┬─────────┬────────────┐
│ _.names │ _.types │ _.scitypes │
├─────────┼─────────┼────────────┤
│ A │ Int64 │ Count │
│ B │ String │ Textual │
└─────────┴─────────┴────────────┘
_.nrows = 4
Here you can see that the scitype of column B is Textual, so you will need to change that to Multiclass. You can use the coerce function to change the scitypes of the columns. Note that in MLJ integer columns are interpreted as count data, so you will also need to coerce column A if you want it to represent continuous data. The coerce method can be used as follows:
julia> coerce!(df, :A => Continuous, :B => Multiclass)
4×2 DataFrame
│ Row │ A │ B │
│ │ Float64 │ Cat… │
├─────┼─────────┼──────┤
│ 1 │ 1.0 │ M │
│ 2 │ 2.0 │ F │
│ 3 │ 3.0 │ F │
│ 4 │ 4.0 │ M │
Now the one-hot encoder will work properly.
ohe = machine(OneHotEncoder(), df)
fit!(ohe)
Xt = MLJ.transform(ohe, df)
4×3 DataFrame
│ Row │ A │ B__F │ B__M │
│ │ Float64 │ Float64 │ Float64 │
├─────┼─────────┼─────────┼─────────┤
│ 1 │ 1.0 │ 0.0 │ 1.0 │
│ 2 │ 2.0 │ 1.0 │ 0.0 │
│ 3 │ 3.0 │ 1.0 │ 0.0 │
│ 4 │ 4.0 │ 0.0 │ 1.0 │
See the section of the MLJ manual on working with categorical data for more information.
I have a julia TimeArray, let's say ta, and I want to build sub_array a TimeArray sub_ta by extracting some of the columns. Some month ago, I used a code similar to minimal example below, but which doesn't work anymore
import TimeSeries
import Dates
dates_index = [ Dates.Date(1970,1,day) for day in [1,2,3,4,5] ]
values = [ [1.0 2.0 3.0 4.0 5.0] ; [10.0 20.0 30.0 40.0 50.0] ; [ 100.0 200.0 300.0 400.0 500.0] ]
ta = TimeSeries.TimeArray( dates_index, transpose(values), [ :col1, :col2, :col3 ] )
sub_ta = ta[ [ :col1 , :col2 ] ]
ERROR: MethodError: no method matching getindex(::TimeSeries.TimeArray{Float64,2,Dates.Date,LinearAlgebra.Transpose{Float64,Array{Float64,2}}}, ::Array{Symbol,1})
Closest candidates are:
getindex(::TimeSeries.TimeArray, ::Integer) at /home/guilhem/.julia/packages/TimeSeries/bbwst/src/timearray.jl:259
getindex(::TimeSeries.TimeArray, ::UnitRange{#s30} where #s30<:Integer) at /home/guilhem/.julia/packages/TimeSeries/bbwst/src/timearray.jl:268
getindex(::TimeSeries.TimeArray, ::AbstractArray{#s30,1} where #s30<:Integer) at /home/guilhem/.julia/packages/TimeSeries/bbwst/src/timearray.jl:276
What seems strange to me is that there is, in the source of the TimeSeries library (in the file timearray.jl) a function getindex which should work if we want to work on many columns.
# array of columns by name
function getindex(ta::TimeArray, ss::Symbol...)
ns = [findcol(ta, s) for s in ss]
TimeArray(timestamp(ta), values(ta)[:, ns], collect(ss), meta(ta))
end
But I think I didn't get the proper way to use it, probably due to the splat operator what I don't really master
problem is both on julia-1.1.0 and julia-1.3.1, with TimeSeries v0.14.0
Finally I think I found the solution, I was quite close :
sub_ta = ta[ [:col1 , col2]...]
The best introduction I found on the ..., the splat operator is on this page (search "..." or "splat") :
enter link description here
What version of TimeSeries are you using?
(tmp) pkg> status
Status `/tmp/Project.toml`
[9e3dc215] TimeSeries v0.16.1
In version 0.16.1, both syntaxes that you mention seem to work:
julia> ta
5×3 TimeSeries.TimeArray{Float64,2,Dates.Date,LinearAlgebra.Transpose{Float64,Array{Float64,2}}} 1970-01-01 to 1970-01-05
│ │ col1 │ col2 │ col3 │
├────────────┼───────┼───────┼───────┤
│ 1970-01-01 │ 1.0 │ 10.0 │ 100.0 │
│ 1970-01-02 │ 2.0 │ 20.0 │ 200.0 │
│ 1970-01-03 │ 3.0 │ 30.0 │ 300.0 │
│ 1970-01-04 │ 4.0 │ 40.0 │ 400.0 │
│ 1970-01-05 │ 5.0 │ 50.0 │ 500.0 │
julia> ta[[:col1, :col2]]
5×2 TimeSeries.TimeArray{Float64,2,Dates.Date,Array{Float64,2}} 1970-01-01 to 1970-01-05
│ │ col1 │ col2 │
├────────────┼───────┼───────┤
│ 1970-01-01 │ 1.0 │ 10.0 │
│ 1970-01-02 │ 2.0 │ 20.0 │
│ 1970-01-03 │ 3.0 │ 30.0 │
│ 1970-01-04 │ 4.0 │ 40.0 │
│ 1970-01-05 │ 5.0 │ 50.0 │
julia> ta[[:col1, :col2]...]
5×2 TimeSeries.TimeArray{Float64,2,Dates.Date,Array{Float64,2}} 1970-01-01 to 1970-01-05
│ │ col1 │ col2 │
├────────────┼───────┼───────┤
│ 1970-01-01 │ 1.0 │ 10.0 │
│ 1970-01-02 │ 2.0 │ 20.0 │
│ 1970-01-03 │ 3.0 │ 30.0 │
│ 1970-01-04 │ 4.0 │ 40.0 │
│ 1970-01-05 │ 5.0 │ 50.0 │
Note that this last version is a rather convoluted way of writing ta[:col1, :col2]:
julia> ta[:col1, :col2]
5×2 TimeSeries.TimeArray{Float64,2,Dates.Date,Array{Float64,2}} 1970-01-01 to 1970-01-05
│ │ col1 │ col2 │
├────────────┼───────┼───────┤
│ 1970-01-01 │ 1.0 │ 10.0 │
│ 1970-01-02 │ 2.0 │ 20.0 │
│ 1970-01-03 │ 3.0 │ 30.0 │
│ 1970-01-04 │ 4.0 │ 40.0 │
│ 1970-01-05 │ 5.0 │ 50.0 │
I've been reading around and it seems there is no very well coherent and fully accepted terminology for the URL parts. Is that true? I'd like to know which standards exists for URL parts terminology. What is the most common? Is there any well established standard?
I found the following:
RFC3986 section 3
foo://example.com:8042/over/there?name=ferret#nose
\_/ \______________/\_________/ \_________/ \__/
| | | | |
scheme authority path query fragment
| _____________________|__
/ \ / \
urn:example:animal:ferret:nose
window.location from Javascript on browsers
protocol://username:password#hostname:port/pathname?search#hash
-----------------------------href------------------------------
-----host----
----------- origin -------------
protocol - protocol scheme of the URL, including the final ':'
hostname - domain name
port - port number
pathname - /pathname
search - ?parameters
hash - #fragment_identifier
username - username specified before the domain name
password - password specified before the domain name
href - the entire URL
origin - protocol://hostname:port
host - hostname:port
NodeJS, module url
Above the line with the URL you see node's url module old API, whilst under the line you see the new API. It seems node shifted from a RFC standard terminology to a more browser friendly standard terminology, that is, similar to browser's windows.location.
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ href │
├──────────┬──┬─────────────────────┬────────────────────────┬───────────────────────────┬───────┤
│ protocol │ │ auth │ host │ path │ hash │
│ │ │ ├─────────────────┬──────┼──────────┬────────────────┤ │
│ │ │ │ hostname │ port │ pathname │ search │ │
│ │ │ │ │ │ ├─┬──────────────┤ │
│ │ │ │ │ │ │ │ query │ │
" https: // user : pass # sub.example.com : 8080 /p/a/t/h ? query=string #hash "
│ │ │ │ │ hostname │ port │ │ │ │
│ │ │ │ ├─────────────────┴──────┤ │ │ │
│ protocol │ │ username │ password │ host │ │ │ │
├──────────┴──┼──────────┴──────────┼────────────────────────┤ │ │ │
│ origin │ │ origin │ pathname │ search │ hash │
├─────────────┴─────────────────────┴────────────────────────┴──────────┴────────────────┴───────┤
│ href │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
Highly ranked article from Matt Cutts
URL: http://video.google.co.uk:80/videoplay?docid=-7246927612831078230&hl=en#00h02m30s
The protocol is http. Other protocols include https, ftp, etc.
The host or hostname is video.google.co.uk.
The subdomain is video.
The domain name is google.co.uk.
The top-level domain or TLD is uk. The uk domain is also referred to as a country-code top-level domain or ccTLD. For google.com, the TLD would be com.
The second-level domain (SLD) is co.uk.
The port is 80, which is the default port for web servers. Other ports are possible; a web server can listen on port 8000, for example. When the port is 80, most people leave out the port.
The path is /videoplay. Path typically refers to a file or location on the web server, e.g. /directory/file.html
This URL has parameters. The name of one parameter is docid and the value of that parameter is 7246927612831078230. URLs can have lots parameters. Parameters start with a question mark (?) and are separated with an ampersand (&).
Some of my concerns:
Is window.location a standard or based on a standard?
Shall I call http:// the protocol or the scheme?
Shall I say host or authority?
Why nor window.location nor node have properties for TLD or other domain parts, when available?
The terminological difference between hostname (example.com) and
host (example.com:8080) is well established?
for node origin does not include username:password# whilst for windows.location it does
I'd like to follow on my code a well established standard or best practises.
The URI standard is STD 66. This is currently mapped to RFC 3986.
So for the generic URI syntax, these terms are authoritative, currently:
scheme
authority
userinfo
host
port
path
query
fragment
Terminology depends on which architectural style/technology you are using.
I prefer REST style for identifying different parts of my url REST URI Standard
But I repeat again there are no single universal standard to represent URL
Java java.net.URL follows RFC 2396 which is an older version of RFC 3986.
Python's urlparse also follows RFC 3986, except for using netloc instead of authority possibly for legacy reasons.
In other words, I'd follow RFC 3986.
I'd like to view the affected files and/or changes that will be made prior to running a method in my custom Rails generator. I've looked through the docs for days and am beginning to think its not possible.
module Mygem
module Generators
class InstallGenerator < Rails::Generators::Base
source_root File.expand_path('../templates', __FILE__)
def copy_theme_files_to_app
directory( source_paths[0] + "/mytemplate", Dir.pwd)
end
end
end
end
In the example above I'm trying to copy the contents of a template directory into the destination app.
├── lib
│ ├── generators
│ │ ├── mygem
│ │ │ ├── templates
│ │ │ │ ├── mytemplate
│ │ │ │ │ ├── app
│ │ │ │ │ │ ├── assets
│ │ │ │ │ │ │ ├── stylesheets
│ │ │ │ │ │ │ │ ├── application.scss
│ │ │ │ │ │ │ │ ├── custom.scss
Here are the contents of the "mytemplate" directory inside of my gem to give a little context. What I'm hoping to see inside of the generators copy_theme_files_to_app method is either an array of new paths to be generated/destroyed or showing the potential conflict between my template's application.scss file and the one in the app.
Is this possible?
I've got an iPad app which presents a modal view controller over the main view controller.
In the modal view controller, there is an image.
┌─────────────────────────────────┐
│ │
│ main VC in background │
│ │
│ ┌───────────────────┐ │
│ │ ┌─────────────┐ │ │
│ │ │ │ │ │
│ │ │ Image │ │ │
│ │ │ │ │ │
│ │ │ │ │ │
│ │ └─────────────┘ │ │
│ │ │ │
│ │ Modal VC │ │
│ │ │ │
│ │ │ │
└──────┴───────────────────┴──────┘
I want to be able to click the image to zoom the image to the size of the WHOLE SCREEN.
If I present the Zoom View Controller from the Modal View Controller, then it will retain the same size as the modal view:
┌─────────────────────────────────┐
│ │
│ main VC in background │
│ │
│ ┌───────────────────┐ │
│ │ │ │
│ │ │ │
│ │ Image │ │
│ │ │ │
│ │ │ │
│ │ │ │
│ ├───────────────────┤ │
│ │ │ │
│ │ Modal VC │ │
│ │ │ │
└──────┴───────────────────┴──────┘
...and if I try to present the Zoom View Controller from the Main View, I will get this error:
Warning: Attempt to present ZoomViewController on MainViewController which is already presenting ModalViewNavigationController
So what is the correct way to present a whole screen view controller over a modal view controller?
Present on the top most modal vc using the OverFullScreen presentation style. Basically present another modal from an already modally presented vc. It should be your ModalViewNavigationController?
What you want to do may not be possible. But you could work around it.
Do you really need to present modally at all? If there's nothing in main VC which a user can interact with, just present "modal VC" non-modally.
But if you do need to prevent users interacting with main VC's other views, you could first place a transparent view over it which covers the screen, preventing any interaction with the other views behind. Then present "modal VC" non-modally in front of that, and then your full screen image in front again.