Skip to content

Instantly share code, notes, and snippets.

View Tiagoperes's full-sized avatar

Tiago Peres França Tiagoperes

View GitHub Profile
@Tiagoperes
Tiagoperes / sbx.c
Last active September 29, 2023 07:57
Routine for real variable SBX crossover taken from the author's implementation (Kalyanmoy Deb)
/* Routine for real variable SBX crossover taken from the author's implementation (Kalyanmoy Deb).
*
* Paper describing the algorithm:
* Title: An Efficient Constraint Handling Method for Genetic Algorithms
* Author: Kalyanmoy Deb
* More info: Appendix A. Page 30.
* URL: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.33.7291&rep=rep1&type=pdf
*
* Commentaries by Tiago Peres França.
*
@Tiagoperes
Tiagoperes / sbx.js
Last active April 26, 2021 09:58
Routine for real variable SBX crossover (Javascript/functional)
/* Routine for real variable SBX crossover based on the original implementation by Kalyanmoy Deb.
* The following implementation is written in Javascript using functional programming, in my
* opinion, it's easier to understand than the original C version (procedural).
*
* Implementation by Tiago Peres França
*
* OBS1: Based on the following code and paper: https://gist.github.com/Tiagoperes/1779d5f1c89bae0cfdb87b1960bba36d
*
* OBS2: functions starting by "_." are from the functional library Lodash.
*
PROCESSO PRINCIPAL:
------------------------------------------------------------------------------------
populacao = gera_populacao;
matriz_distancias = calcular_matriz_distancias(populacao, objetivos);
calcular_fitness(populacao, objetivos, matriz_distancias);
arquivo = selecionar_arquivo(populacao, tam_arquivo);
for (i = 0; i < numero_geracoes; i++) {
pais = selecionar_pais(arquivo, tam_populacao);
import axios from 'axios'
const api = axios.create({
mode: 'cors',
baseURL: 'http://localhost:3000',
})
// if we don't write the next line, our resources will receive the entire response in the data field. We don't want that.
api.interceptors.response.use(response => response.data)
import createResource from '@zup-next/redux-resource'
import api from '../api'
const profile = createResource('PROFILE', {
load: api.loadProfile,
update: api.saveProfile,
})
const catalog = createResource('CATALOG', { load: api.loadCatalog })
import { createStore, applyMiddleware, combineReducers } from 'redux'
import createSagaMiddleware from 'redux-saga'
import resources from './resources'
import { createEffects } from '@zup-next/redux-resource'
const reducers = combineReducers({
catalog: resources.catalog.reducers,
order: resources.order.reducers,
profile: resources.profile.reducers,
wallet: resources.wallet.reducers,
import React, { PureComponent } from 'react'
import { connect } from 'react-redux'
import resources from '../../store/resources'
import { HeaderBar, HeaderContent, Top, Bottom } from './styled'
import { isPristine, isLoading, hasLoadError } from '@zup-next/redux-resource'
const Loading = () => <HeaderBar><HeaderContent>Loading...</HeaderContent></HeaderBar>
const Error = () => <HeaderBar><HeaderContent>Error!</HeaderContent></HeaderBar>
if (profile.load.status === 'pristine') || wallet.load.status === 'pristine') return null
if (profile.load.status === 'pending') || wallet.load.status === 'pending') return <Loading />
if (profile.load.status === 'error') || wallet.load.status === 'error') return <Error />
class Home extends PureComponent {
componentDidMount() {
const { loadCatalog } = this.props
loadCatalog()
}
render() {
const { catalog } = this.props
const findMovieById = (catalog, id) => find(catalog.data, { id: parseInt(id) })
class Movie extends PureComponent {
componentDidMount() {
const { loadCatalog } = this.props
loadCatalog()
}
render() {