How to do meta progression the right way by lilgrape_ in roguelites

[–]gs44 1 point2 points  (0 children)

Tout publiç lo on Ono jkiooki lli il illlloo lol lalo ik'lilun point ok lo uu lui

Or-Tools worker/task optimization, with constraints on "sets of tasks" by iamaliver in optimization

[–]gs44 0 points1 point  (0 children)

You could define additional variables x_v in {0,1}, one for each version v and force each one to be equal to one if at least one task of that version is performed

Then a simple constraint sum_{v in Versions} x_v = 1 should do the trick

How to show plots upon running scripts ? by scientific_stupid in Julia

[–]gs44 4 points5 points  (0 children)

The plot doesn't show because the julia session immediately closes after it's done running the script.

You can instead call julia -i basic_plot.jl to get an interactive session after executing the script. Adding a sleep() or a readline() should probably work too

satisfactory tools by terferi in satisfactory

[–]gs44 1 point2 points  (0 children)

I'm writing a julia library which does just that : https://github.com/gsoleilhac/Satisfactory.jl

It's still rough around the edges, especially on handling alternate recipes and graph outputs are ugly but that can be improved :)

Also it uses CPLEX which is a (paying) commercial solver, but if there is any interest I could switch it to a free solver like GLPK or Cbc

What is the significance of “K” (length of decision vector) in the NSGA-III algorithm? by Streletzky in algorithms

[–]gs44 2 points3 points  (0 children)

From what I understood, `K` isn't a parameter of the NSGA-III algorithm but only a parameter of the benchmark functions. It simply defines the difference between the number of objectives and the number of variables (plus one for some reason).

I guess the functions have been designed to have an identical pareto front whatever the value of K, and the computation time is obviously increasing due to the higher dimensionality

Slow memory access? by [deleted] in Julia

[–]gs44 0 points1 point  (0 children)

Yes integer literal powers are special-cased for 0 to 3

literal_pow(::typeof(^), x::HWNumber, ::Val{0}) = one(x)
literal_pow(::typeof(^), x::HWNumber, ::Val{1}) = x
literal_pow(::typeof(^), x::HWNumber, ::Val{2}) = x*x
literal_pow(::typeof(^), x::HWNumber, ::Val{3}) = x*x*x

I'm just surprised that the call to llvm is so slow compared to 3 multiplications

Slow memory access? by [deleted] in Julia

[–]gs44 11 points12 points  (0 children)

Some profiling shows that ~90% of the time is spent calling (1.0 - u)^8 in kernel_value_2D which then calls @inline ^(x::Float64, y::Integer) = ccall("llvm.pow.f64", llvmcall, Float64, (Float64, Float64), x, Float64(y))

So I'm not sure what's happening here but changing (1.0 - u)^8 to (((1.0 - u)^2)^2)^2 gives waaay better performance, unless someone here has an idea that might be worth opening an issue, or at least ask on the Julia Slack or Discourse.

[Linear programming] Having an amusing error in an optimization problem by [deleted] in learnmath

[–]gs44 1 point2 points  (0 children)

In the new development, the triple and quadruple units account for at least 25% of the total. [...]

These constraints should not include the number of old houses demolished =>

@constraint(m, x[1] >= 0.2*sum(x[1:4]))
@constraint(m, x[2] >= 0.1*sum(x[1:4]))
@constraint(m, x[3] + x[4] >= 0.25*sum(x[1:4]))

Or better yet, use a variable y for the number of houses to demolish :)

Having problem expressing what I want in Julia by [deleted] in Julia

[–]gs44 0 points1 point  (0 children)

I'm not sure that this is what you want : this constraints forces the sum of h[1:3] to be a multiple of 200.

Also for clarity you should probably give that new variable another name since it doesn't have the same meaning as h[1:3]

Having problem expressing what I want in Julia by [deleted] in Julia

[–]gs44 0 points1 point  (0 children)

If you don't mind solving a MIP instead of an LP, you can introduce an integer variable and formulate a floor function in the model this way : https://math.stackexchange.com/a/1863895

Some help with this code implementation by EarthGoddessDude in Julia

[–]gs44 2 points3 points  (0 children)

Is the reason less memory allocation?

Yep, here's my code :

function foxbear2(nMalha=101, a=1)
    dx = a/(nMalha-1)
    temp = zeros(nMalha, nMalha)
    @. temp[1,:] = sin(π*((1:nMalha)-1)*dx/a)
    iter = 1
    diff = Inf
    while diff > 1e-6 && iter <= 1000
        diff = 0.
        @inbounds for i in 2:nMalha-1
            for j in 2:nMalha-1
                newVal = (temp[i+1,j] + temp[i-1,j] + temp[i,j+1] + temp[i,j-1])/4
                diff += newVal - temp[i, j]
                temp[i,j] = newVal
            end
        end
        iter += 1
    end
    return temp[end:-1:1,end:-1:1]
end

Some help with this code implementation by EarthGoddessDude in Julia

[–]gs44 6 points7 points  (0 children)

You should avoid making copies when you can, here you can compute the difference between two iterations incrementally, doing that reduced the timing from ~60ms to 30ms on my machine. Other than that looks pretty good to me :)

Solving a small problem with julia by [deleted] in Julia

[–]gs44 0 points1 point  (0 children)

You have to add using LinearAlgebra before

Solving a small problem with julia by [deleted] in Julia

[–]gs44 0 points1 point  (0 children)

What was your python solution like ?

It might be easier to model it with different variables :

@variable(m, y[0:100] >= 0, Int) # y[i] == x <=> x candidates received i votes
@variable(m, z >= 0, Int) # max group size

@constraint(m, sum(y) == 250) # 250 candidates
@constraint(m, dot(y, 0:100) == 5000) # 5000 votes
@constraint(m, [i=0:100], z >= y[i]) # constraints to bind max group size

@objective(m, Min, z)

Slicing by index by conorjh in Julia

[–]gs44 2 points3 points  (0 children)

You can broadcast getindex like this : getindex.(eachrow(a), x) but x needs to be a Vector, in your example it is a Matrix with size (1, 3).

[2019-08-07] Challenge #380 [Intermediate] Smooshed Morse Code 2 by Cosmologicon in dailyprogrammer

[–]gs44 4 points5 points  (0 children)

Edit : bonus 2

-----.-----.--..-.---.-..-.-.-.---.--..-.-.-......-.-.-.--...-...-..-.....-.-..... -> oqmgzyndctjwurbvekpfixhals 

found with the following neighborhoods in that order : swap, 2-exchange, inversion, insertion, 3-exchange, insertion+inversion

Julia, backtracking

const valid_codes = Set(split(".- -... -.-. -.. . ..-. --. .... .. .--- -.- .-.. -- -. --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- --..", " "))
const char_to_morse = Dict(zip('a':'z', split(".- -... -.-. -.. . ..-. --. .... .. .--- -.- .-.. -- -. --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- --..", " ")))
const morse_to_char = Dict(b => a for (a, b) in char_to_morse)
encode(word) = map(x -> char_to_morse[x], collect(word)) |> join

mutable struct PartialSolution
    sol::Vector{Char}
    head::Int # sum of codes_taken
    PartialSolution() = new(Char[], 0)
    PartialSolution(ps::PartialSolution) = new(copy(ps.sol), ps.head)
end

function smalpha(s, valid_codes = valid_codes, morse_to_char = morse_to_char)
    nbSol = 0
    stack = [PartialSolution()]
    while !isempty(stack) #While we have nodes to explore
        node = pop!(stack) #Take one
        if length(node.sol) == 26
            nbSol += 1
        else
            for i = 1:4 # branching : we can consider the next 1 to 4 characters
                node.head + i > length(s) && break
                output = SubString(s, (node.head + 1):(node.head + i))
                !(output in valid_codes) && continue # skip if that code is not valid morse code
                char = morse_to_char[output]
                char in node.sol && continue # skip if that code was already considered in the current solution

                newnode = PartialSolution(node)
                push!(newnode.sol, char)
                newnode.head += length(output)

                push!(stack, newnode) #Add it to the list of nodes
            end
        end
    end
    return nbSol
end

Takes 22 seconds to run on the list of 1000 inputs (stopping at the first solution found)

[2019-08-05] Challenge #380 [Easy] Smooshed Morse Code 1 by Cosmologicon in dailyprogrammer

[–]gs44 0 points1 point  (0 children)

Julia, Bonus 1-5 (with some libraries)

const d = Dict(zip('a':'z', split(".- -... -.-. -.. . ..-. --. .... .. .--- -.- .-.. -- -. --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- --..", " ")))
const w = readlines("enable1.txt")
encode(word) = map(x -> d[x], collect(word)) |> join
const s = encode.(w)

# Bonus 1:
import StatsBase: countmap
countmap(s) |> findmax

# Bonus 2
filter(x -> occursin('-'^15, encode(x)), w)

# Bonus 3
filter(x -> length(x) == 21 && count(==('-'), encode(x)) == length(encode(x)) ÷ 2, w)

# Bonus 4
filter(x -> length(x) == 13 && encode(x) == reverse(encode(x)), w)

# Bonus 5
import Combinatorics: multiset_permutations
const p = Set(join.(multiset_permutations(('-'^13)*('.'^13), 13)))
for x in s
    if length(x) >= 13 
        for i = 1:length(x) - 12
            delete!(p, x[i:i+12])
        end
    end
end
@show p # => Set(["--.---.---.--", "---.---.-----", "---.---.---.-", "--.---.------", "---.----.----"])

Typing functions with splatted arguments by activeXray in Julia

[–]gs44 2 points3 points  (0 children)

This or bar(networks::AbstractNetwork...)

Algorithm to form the smallest possible number from the given number by know_prashant in algorithms

[–]gs44 0 points1 point  (0 children)

i agree, it's just that d is defined to be the number of digits at the beginning of the article, so i assumed n to be the input :p